From 97a12081108844b2fb7dccd8a4ac682bff22a51f Mon Sep 17 00:00:00 2001 From: Linquize Date: Mon, 26 Aug 2013 21:39:32 +0800 Subject: [PATCH 1/2] Generate AssemblyInfo.cs --- ILSpy/Languages/CSharpLanguage.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index 86985264e..415337d26 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -423,6 +423,25 @@ namespace ICSharpCode.ILSpy return true; } + IEnumerable> WriteAssemblyInfo(ModuleDefinition module, DecompilationOptions options, HashSet directories) + { + // don't automatically load additional assemblies when an assembly node is selected in the tree view + using (LoadedAssembly.DisableAssemblyLoad()) + { + AstBuilder codeDomBuilder = CreateAstBuilder(options, currentModule: module); + codeDomBuilder.AddAssembly(module, onlyAssemblyLevel: true); + codeDomBuilder.RunTransformations(transformAbortCondition); + + string prop = "Properties"; + if (directories.Add("Properties")) + Directory.CreateDirectory(Path.Combine(options.SaveAsProjectDirectory, prop)); + string assemblyInfo = Path.Combine(prop, "AssemblyInfo" + this.FileExtension); + using (StreamWriter w = new StreamWriter(Path.Combine(options.SaveAsProjectDirectory, assemblyInfo))) + codeDomBuilder.GenerateCode(new PlainTextOutput(w)); + return new Tuple[] { Tuple.Create("Compile", assemblyInfo) }; + } + } + IEnumerable> WriteCodeFilesInProject(ModuleDefinition module, DecompilationOptions options, HashSet directories) { var files = module.Types.Where(t => IncludeTypeWhenDecompilingProject(t, options)).GroupBy( @@ -452,7 +471,7 @@ namespace ICSharpCode.ILSpy } }); AstMethodBodyBuilder.PrintNumberOfUnhandledOpcodes(); - return files.Select(f => Tuple.Create("Compile", f.Key)); + return files.Select(f => Tuple.Create("Compile", f.Key)).Concat(WriteAssemblyInfo(module, options, directories)); } #endregion From 8d2bee69af510e48b9ddbce027c2dc90cb7773b1 Mon Sep 17 00:00:00 2001 From: Linquize Date: Mon, 26 Aug 2013 21:41:04 +0800 Subject: [PATCH 2/2] Generate AssemblyInfo.vb --- ILSpy/VB/VBLanguage.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ILSpy/VB/VBLanguage.cs b/ILSpy/VB/VBLanguage.cs index e6a655f38..c730802bc 100644 --- a/ILSpy/VB/VBLanguage.cs +++ b/ILSpy/VB/VBLanguage.cs @@ -248,6 +248,25 @@ namespace ICSharpCode.ILSpy.VB return true; } + IEnumerable> WriteAssemblyInfo(ModuleDefinition module, DecompilationOptions options, HashSet directories) + { + // don't automatically load additional assemblies when an assembly node is selected in the tree view + using (LoadedAssembly.DisableAssemblyLoad()) + { + AstBuilder codeDomBuilder = CreateAstBuilder(options, currentModule: module); + codeDomBuilder.AddAssembly(module, onlyAssemblyLevel: true); + codeDomBuilder.RunTransformations(transformAbortCondition); + + string prop = "Properties"; + if (directories.Add("Properties")) + Directory.CreateDirectory(Path.Combine(options.SaveAsProjectDirectory, prop)); + string assemblyInfo = Path.Combine(prop, "AssemblyInfo" + this.FileExtension); + using (StreamWriter w = new StreamWriter(Path.Combine(options.SaveAsProjectDirectory, assemblyInfo))) + codeDomBuilder.GenerateCode(new PlainTextOutput(w)); + return new Tuple[] { Tuple.Create("Compile", assemblyInfo) }; + } + } + IEnumerable> WriteCodeFilesInProject(ModuleDefinition module, DecompilationOptions options, HashSet directories) { var files = module.Types.Where(t => IncludeTypeWhenDecompilingProject(t, options)).GroupBy( @@ -276,7 +295,7 @@ namespace ICSharpCode.ILSpy.VB } }); AstMethodBodyBuilder.PrintNumberOfUnhandledOpcodes(); - return files.Select(f => Tuple.Create("Compile", f.Key)); + return files.Select(f => Tuple.Create("Compile", f.Key)).Concat(WriteAssemblyInfo(module, options, directories)); } #endregion