From c581cec0dd0342e839bd42979e4c6a5828773194 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 12 Jun 2016 08:05:34 +0900 Subject: [PATCH] remove System.Runtime.Versioning.TargetFrameworkAttribute when exporting assembly as project --- .../Transforms/EscapeInvalidIdentifiers.cs | 24 +++++++++++++++++++ ILSpy/Languages/CSharpLanguage.cs | 1 + 2 files changed, 25 insertions(+) diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs b/ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs index 9ea3cfe68..5f487577e 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs @@ -19,6 +19,7 @@ using System; using System.Linq; using ICSharpCode.NRefactory.CSharp; +using ICSharpCode.NRefactory.Semantics; namespace ICSharpCode.Decompiler.CSharp.Transforms { @@ -54,4 +55,27 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms } } } + + /// + /// This transform is used to remove assembly-attributes that are generated by the compiler, + /// thus don't need to be declared. (We have to remove them, in order to avoid conflicts while compiling.) + /// + /// This transform is only enabled, when exporting a full assembly as project. + public class RemoveCompilerGeneratedAssemblyAttributes : IAstTransform + { + public void Run(AstNode rootNode, TransformContext context) + { + foreach (var section in rootNode.Children.OfType()) { + if (section.AttributeTarget != "assembly") + continue; + foreach (var attribute in section.Attributes) { + var trr = attribute.Type.Annotation(); + if (trr != null && trr.Type.FullName == "System.Runtime.Versioning.TargetFrameworkAttribute") + attribute.Remove(); + } + if (section.Attributes.Count == 0) + section.Remove(); + } + } + } } diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index b26f17051..69c783ff3 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -492,6 +492,7 @@ namespace ICSharpCode.ILSpy { CSharpDecompiler decompiler = new CSharpDecompiler(ts, options.DecompilerSettings); decompiler.AstTransforms.Add(new EscapeInvalidIdentifiers()); + decompiler.AstTransforms.Add(new RemoveCompilerGeneratedAssemblyAttributes()); SyntaxTree syntaxTree = decompiler.DecompileModuleAndAssemblyAttributes(); string prop = "Properties";