Browse Source

fixes #1646 - netcoreapp uses wrong mscorlib (#1649)

* fixes #1646 - netcoreapp uses wrong mscorlib

* optimize framework detection

* refactor decompiler runtime to a enum
pull/1652/head
Jochen Kühner 6 years ago committed by Siegfried Pammer
parent
commit
427a459bfd
  1. 49
      ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs

49
ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs

@ -29,6 +29,18 @@ namespace ICSharpCode.Decompiler.Metadata @@ -29,6 +29,18 @@ namespace ICSharpCode.Decompiler.Metadata
// This inspired by Mono.Cecil's BaseAssemblyResolver/DefaultAssemblyResolver.
public class UniversalAssemblyResolver : IAssemblyResolver
{
static UniversalAssemblyResolver()
{
// TODO : test whether this works with Mono on *Windows*, not sure if we'll
// ever need this...
if (Type.GetType("Mono.Runtime") != null)
decompilerRuntime = DecompilerRuntime.Mono;
else if (Environment.OSVersion.Platform == PlatformID.Unix)
decompilerRuntime = DecompilerRuntime.Mono;
else if (typeof(object).Assembly.GetName().Name == "System.Private.CoreLib")
decompilerRuntime = DecompilerRuntime.NETCoreApp;
}
DotNetCorePathFinder dotNetCorePathFinder;
readonly bool throwOnError;
readonly PEStreamOptions streamOptions;
@ -38,21 +50,7 @@ namespace ICSharpCode.Decompiler.Metadata @@ -38,21 +50,7 @@ namespace ICSharpCode.Decompiler.Metadata
readonly List<string> directories = new List<string>();
readonly List<string> gac_paths = GetGacPaths();
HashSet<string> targetFrameworkSearchPaths;
/// <summary>
/// Detect whether we're in a Mono environment.
/// </summary>
/// <remarks>This is used whenever we're trying to decompile a plain old .NET framework assembly on Unix.</remarks>
static bool DetectMono()
{
// TODO : test whether this works with Mono on *Windows*, not sure if we'll
// ever need this...
if (Type.GetType("Mono.Runtime") != null)
return true;
if (Environment.OSVersion.Platform == PlatformID.Unix)
return true;
return false;
}
static readonly DecompilerRuntime decompilerRuntime;
public void AddSearchDirectory(string directory)
{
@ -77,6 +75,13 @@ namespace ICSharpCode.Decompiler.Metadata @@ -77,6 +75,13 @@ namespace ICSharpCode.Decompiler.Metadata
Silverlight
}
enum DecompilerRuntime
{
NETFramework,
NETCoreApp,
Mono
}
string targetFramework;
TargetFrameworkIdentifier targetFrameworkIdentifier;
Version targetFrameworkVersion;
@ -291,7 +296,7 @@ namespace ICSharpCode.Decompiler.Metadata @@ -291,7 +296,7 @@ namespace ICSharpCode.Decompiler.Metadata
return assembly;
var framework_dir = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName);
var framework_dirs = DetectMono()
var framework_dirs = decompilerRuntime == DecompilerRuntime.Mono
? new[] { framework_dir, Path.Combine(framework_dir, "Facades") }
: new[] { framework_dir };
@ -367,11 +372,13 @@ namespace ICSharpCode.Decompiler.Metadata @@ -367,11 +372,13 @@ namespace ICSharpCode.Decompiler.Metadata
var version = reference.Version;
var corlib = typeof(object).Assembly.GetName();
if (corlib.Version == version || IsSpecialVersionOrRetargetable(reference))
return typeof(object).Module.FullyQualifiedName;
if (decompilerRuntime != DecompilerRuntime.NETCoreApp) {
if (corlib.Version == version || IsSpecialVersionOrRetargetable(reference))
return typeof(object).Module.FullyQualifiedName;
}
string path;
if (DetectMono()) {
if (decompilerRuntime == DecompilerRuntime.Mono) {
path = GetMonoMscorlibBasePath(version);
} else {
path = GetMscorlibBasePath(version, reference.PublicKeyToken.ToHexString(8));
@ -460,7 +467,7 @@ namespace ICSharpCode.Decompiler.Metadata @@ -460,7 +467,7 @@ namespace ICSharpCode.Decompiler.Metadata
static List<string> GetGacPaths()
{
if (DetectMono())
if (decompilerRuntime == DecompilerRuntime.Mono)
return GetDefaultMonoGacPaths();
var paths = new List<string>(2);
@ -510,7 +517,7 @@ namespace ICSharpCode.Decompiler.Metadata @@ -510,7 +517,7 @@ namespace ICSharpCode.Decompiler.Metadata
if (reference.PublicKeyToken == null || reference.PublicKeyToken.Length == 0)
return null;
if (DetectMono())
if (decompilerRuntime == DecompilerRuntime.Mono)
return GetAssemblyInMonoGac(reference);
return GetAssemblyInNetGac(reference);

Loading…
Cancel
Save