From 9b27ced6afac7cba34c61f0f1e705b27f9685b13 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Tue, 29 Sep 2020 21:49:14 +0200 Subject: [PATCH] Avoid reference on ICSharpCode.Decompiler in VS AddIn. This way we don't need to load SRM 5 within the VS process. --- .../Metadata/AssemblyReferences.cs | 4 ++ .../Metadata/UniversalAssemblyResolver.cs | 2 + ILSpy.AddIn/AssemblyFileFinder.cs | 1 - ILSpy.AddIn/Commands/OpenReferenceCommand.cs | 6 --- .../Commands/ProjectReferenceForILSpy.cs | 8 +--- ILSpy.AddIn/Decompiler/Dummy.cs | 30 +++++++++++++ ILSpy.AddIn/ILSpy.AddIn.csproj | 42 ++++++++++++++----- 7 files changed, 68 insertions(+), 25 deletions(-) create mode 100644 ILSpy.AddIn/Decompiler/Dummy.cs diff --git a/ICSharpCode.Decompiler/Metadata/AssemblyReferences.cs b/ICSharpCode.Decompiler/Metadata/AssemblyReferences.cs index d2f16d675..68c19d503 100644 --- a/ICSharpCode.Decompiler/Metadata/AssemblyReferences.cs +++ b/ICSharpCode.Decompiler/Metadata/AssemblyReferences.cs @@ -44,8 +44,10 @@ namespace ICSharpCode.Decompiler.Metadata public interface IAssemblyResolver { +#if !VSADDIN PEFile Resolve(IAssemblyReference reference); PEFile ResolveModule(PEFile mainModule, string moduleName); +#endif bool IsGacAssembly(IAssemblyReference reference); } @@ -169,6 +171,7 @@ namespace ICSharpCode.Decompiler.Metadata } } +#if !VSADDIN public class AssemblyReference : IAssemblyReference { static readonly SHA1 sha1 = SHA1.Create(); @@ -226,4 +229,5 @@ namespace ICSharpCode.Decompiler.Metadata return FullName; } } +#endif } diff --git a/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs b/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs index cdcf8c141..03c27c702 100644 --- a/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs +++ b/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs @@ -157,6 +157,7 @@ namespace ICSharpCode.Decompiler.Metadata return (identifier, version ?? ZeroVersion); } +#if !VSADDIN public PEFile Resolve(IAssemblyReference name) { var file = FindAssemblyFile(name); @@ -181,6 +182,7 @@ namespace ICSharpCode.Decompiler.Metadata } return new PEFile(moduleFileName, new FileStream(moduleFileName, FileMode.Open, FileAccess.Read), streamOptions, metadataOptions); } +#endif public virtual bool IsGacAssembly(IAssemblyReference reference) { diff --git a/ILSpy.AddIn/AssemblyFileFinder.cs b/ILSpy.AddIn/AssemblyFileFinder.cs index d5a443575..82fe7db30 100644 --- a/ILSpy.AddIn/AssemblyFileFinder.cs +++ b/ILSpy.AddIn/AssemblyFileFinder.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Text.RegularExpressions; using ICSharpCode.Decompiler.Metadata; -using ICSharpCode.Decompiler.Util; namespace ICSharpCode.ILSpy.AddIn { diff --git a/ILSpy.AddIn/Commands/OpenReferenceCommand.cs b/ILSpy.AddIn/Commands/OpenReferenceCommand.cs index c01e5e077..fd4a9dc82 100644 --- a/ILSpy.AddIn/Commands/OpenReferenceCommand.cs +++ b/ILSpy.AddIn/Commands/OpenReferenceCommand.cs @@ -1,16 +1,10 @@ using System; -using System.Collections.Generic; using System.Linq; using EnvDTE; -using ICSharpCode.Decompiler.Metadata; - -using Microsoft.CodeAnalysis; using Microsoft.VisualStudio.Shell; -using Mono.Cecil; - using VSLangProj; namespace ICSharpCode.ILSpy.AddIn.Commands diff --git a/ILSpy.AddIn/Commands/ProjectReferenceForILSpy.cs b/ILSpy.AddIn/Commands/ProjectReferenceForILSpy.cs index 07a53ddac..8263bac44 100644 --- a/ILSpy.AddIn/Commands/ProjectReferenceForILSpy.cs +++ b/ILSpy.AddIn/Commands/ProjectReferenceForILSpy.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; using EnvDTE; @@ -10,8 +6,6 @@ using ICSharpCode.Decompiler.Metadata; using Microsoft.VisualStudio.Shell; -using Mono.Cecil; - namespace ICSharpCode.ILSpy.AddIn.Commands { /// diff --git a/ILSpy.AddIn/Decompiler/Dummy.cs b/ILSpy.AddIn/Decompiler/Dummy.cs new file mode 100644 index 000000000..db6431339 --- /dev/null +++ b/ILSpy.AddIn/Decompiler/Dummy.cs @@ -0,0 +1,30 @@ +// Dummy types so that we can use compile some ICS.Decompiler classes in the AddIn context +// without depending on SRM etc. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace ICSharpCode.Decompiler +{ + public class ReferenceLoadInfo + { + public void AddMessage(params object[] args) { } + } + + enum MessageKind { Warning } + + public static class MetadataExtensions + { + public static string ToHexString(this IEnumerable bytes, int estimatedLength) + { + if (bytes == null) + throw new ArgumentNullException(nameof(bytes)); + + StringBuilder sb = new StringBuilder(estimatedLength * 2); + foreach (var b in bytes) + sb.AppendFormat("{0:x2}", b); + return sb.ToString(); + } + } +} diff --git a/ILSpy.AddIn/ILSpy.AddIn.csproj b/ILSpy.AddIn/ILSpy.AddIn.csproj index 6c4096184..31fc45fc9 100644 --- a/ILSpy.AddIn/ILSpy.AddIn.csproj +++ b/ILSpy.AddIn/ILSpy.AddIn.csproj @@ -44,7 +44,7 @@ - + @@ -53,7 +53,6 @@ - false false @@ -61,6 +60,18 @@ + + + + + + + + + + + + @@ -70,6 +81,7 @@ + @@ -145,14 +157,14 @@ Designer - - - Designer - - - true - Always - + + + Designer + + + true + Always + Menus.ctmenu Designer @@ -189,8 +201,16 @@ true + + TRACE;VSADDIN + + + + TRACE;VSADDIN + + - \ No newline at end of file +