Browse Source

remove System.Runtime.Versioning.TargetFrameworkAttribute when exporting assembly as project

pull/728/head
Siegfried Pammer 9 years ago
parent
commit
c581cec0dd
  1. 24
      ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs
  2. 1
      ILSpy/Languages/CSharpLanguage.cs

24
ICSharpCode.Decompiler/CSharp/Transforms/EscapeInvalidIdentifiers.cs

@ -19,6 +19,7 @@ @@ -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 @@ -54,4 +55,27 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
}
}
}
/// <summary>
/// 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.)
/// </summary>
/// <remarks>This transform is only enabled, when exporting a full assembly as project.</remarks>
public class RemoveCompilerGeneratedAssemblyAttributes : IAstTransform
{
public void Run(AstNode rootNode, TransformContext context)
{
foreach (var section in rootNode.Children.OfType<AttributeSection>()) {
if (section.AttributeTarget != "assembly")
continue;
foreach (var attribute in section.Attributes) {
var trr = attribute.Type.Annotation<TypeResolveResult>();
if (trr != null && trr.Type.FullName == "System.Runtime.Versioning.TargetFrameworkAttribute")
attribute.Remove();
}
if (section.Attributes.Count == 0)
section.Remove();
}
}
}
}

1
ILSpy/Languages/CSharpLanguage.cs

@ -492,6 +492,7 @@ namespace ICSharpCode.ILSpy @@ -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";

Loading…
Cancel
Save