Browse Source

Avoid reference on ICSharpCode.Decompiler in VS AddIn.

This way we don't need to load SRM 5 within the VS process.
pull/2178/head
Daniel Grunwald 5 years ago
parent
commit
9b27ced6af
  1. 4
      ICSharpCode.Decompiler/Metadata/AssemblyReferences.cs
  2. 2
      ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs
  3. 1
      ILSpy.AddIn/AssemblyFileFinder.cs
  4. 6
      ILSpy.AddIn/Commands/OpenReferenceCommand.cs
  5. 8
      ILSpy.AddIn/Commands/ProjectReferenceForILSpy.cs
  6. 30
      ILSpy.AddIn/Decompiler/Dummy.cs
  7. 42
      ILSpy.AddIn/ILSpy.AddIn.csproj

4
ICSharpCode.Decompiler/Metadata/AssemblyReferences.cs

@ -44,8 +44,10 @@ namespace ICSharpCode.Decompiler.Metadata @@ -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 @@ -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 @@ -226,4 +229,5 @@ namespace ICSharpCode.Decompiler.Metadata
return FullName;
}
}
#endif
}

2
ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs

@ -157,6 +157,7 @@ namespace ICSharpCode.Decompiler.Metadata @@ -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 @@ -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)
{

1
ILSpy.AddIn/AssemblyFileFinder.cs

@ -3,7 +3,6 @@ using System.Linq; @@ -3,7 +3,6 @@ using System.Linq;
using System.Text.RegularExpressions;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.Util;
namespace ICSharpCode.ILSpy.AddIn
{

6
ILSpy.AddIn/Commands/OpenReferenceCommand.cs

@ -1,16 +1,10 @@ @@ -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

8
ILSpy.AddIn/Commands/ProjectReferenceForILSpy.cs

@ -1,8 +1,4 @@ @@ -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; @@ -10,8 +6,6 @@ using ICSharpCode.Decompiler.Metadata;
using Microsoft.VisualStudio.Shell;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.AddIn.Commands
{
/// <summary>

30
ILSpy.AddIn/Decompiler/Dummy.cs

@ -0,0 +1,30 @@ @@ -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<byte> 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();
}
}
}

42
ILSpy.AddIn/ILSpy.AddIn.csproj

@ -44,7 +44,7 @@ @@ -44,7 +44,7 @@
<Import Project="..\packages.props" />
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.SDK " Version="15.9.3" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="15.9.3" />
<!-- Intentionally using an old Roslyn version in the AddIn, so that we stay compatible with old VS versions. -->
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.4.0" />
@ -53,7 +53,6 @@ @@ -53,7 +53,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.csproj" />
<ProjectReference Include="..\ILSpy\ILSpy.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<Private>false</Private>
@ -61,6 +60,18 @@ @@ -61,6 +60,18 @@
</ItemGroup>
<ItemGroup>
<Compile Include="..\ICSharpCode.Decompiler\Metadata\AssemblyReferences.cs" Link="Decompiler\AssemblyReferences.cs" />
<Compile Include="..\ICSharpCode.Decompiler\Metadata\DotNetCorePathFinder.cs" Link="Decompiler\DotNetCorePathFinder.cs" />
<Compile Include="..\ICSharpCode.Decompiler\Metadata\LightJson\JsonArray.cs" Link="Decompiler\LightJson\JsonArray.cs" />
<Compile Include="..\ICSharpCode.Decompiler\Metadata\LightJson\JsonObject.cs" Link="Decompiler\LightJson\JsonObject.cs" />
<Compile Include="..\ICSharpCode.Decompiler\Metadata\LightJson\JsonValue.cs" Link="Decompiler\LightJson\JsonValue.cs" />
<Compile Include="..\ICSharpCode.Decompiler\Metadata\LightJson\JsonValueType.cs" Link="Decompiler\LightJson\JsonValueType.cs" />
<Compile Include="..\ICSharpCode.Decompiler\Metadata\LightJson\Serialization\JsonParseException.cs" Link="Decompiler\LightJson\Serialization\JsonParseException.cs" />
<Compile Include="..\ICSharpCode.Decompiler\Metadata\LightJson\Serialization\JsonReader.cs" Link="Decompiler\LightJson\Serialization\JsonReader.cs" />
<Compile Include="..\ICSharpCode.Decompiler\Metadata\LightJson\Serialization\TextPosition.cs" Link="Decompiler\LightJson\Serialization\TextPosition.cs" />
<Compile Include="..\ICSharpCode.Decompiler\Metadata\LightJson\Serialization\TextScanner.cs" Link="Decompiler\LightJson\Serialization\TextScanner.cs" />
<Compile Include="..\ICSharpCode.Decompiler\Metadata\UniversalAssemblyResolver.cs" Link="UniversalAssemblyResolver.cs" />
<Compile Include="..\ICSharpCode.Decompiler\Util\EmptyList.cs" Link="Decompiler\EmptyList.cs" />
<Compile Include="..\ILSpy\NativeMethods.cs" Link="NativeMethods.cs" />
<Compile Include="Commands\AssemblyReferenceForILSpy.cs" />
<Compile Include="Commands\NuGetReferenceForILSpy.cs" />
@ -70,6 +81,7 @@ @@ -70,6 +81,7 @@
<Compile Include="Commands\OpenILSpyCommand.cs" />
<Compile Include="Commands\OpenProjectOutputCommand.cs" />
<Compile Include="Commands\OpenReferenceCommand.cs" />
<Compile Include="Decompiler\Dummy.cs" />
<Compile Include="Guids.cs" />
<Compile Include="ILSpyInstance.cs" />
<Compile Include="Resources.Designer.cs">
@ -145,14 +157,14 @@ @@ -145,14 +157,14 @@
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<None Include="ILSpyAddIn.vsct">
<SubType>Designer</SubType>
</None>
<Content Include="zh-Hans\extension.vsixlangpack">
<IncludeInVSIX>true</IncludeInVSIX>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<ItemGroup>
<None Include="ILSpyAddIn.vsct">
<SubType>Designer</SubType>
</None>
<Content Include="zh-Hans\extension.vsixlangpack">
<IncludeInVSIX>true</IncludeInVSIX>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<VSCTCompile Include="ILSpyAddIn.en-US.vsct">
<ResourceName>Menus.ctmenu</ResourceName>
<SubType>Designer</SubType>
@ -189,8 +201,16 @@ @@ -189,8 +201,16 @@
<UseCodebase>true</UseCodebase>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;VSADDIN</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>TRACE;VSADDIN</DefineConstants>
</PropertyGroup>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="Exists('$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets')" />
</Project>
</Project>

Loading…
Cancel
Save