Browse Source

Add FindDotNetExeDirectory

pull/848/head
Siegfried Pammer 8 years ago
parent
commit
d4581a477c
  1. 25
      ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs
  2. 1
      ILSpy/LoadedAssembly.cs

25
ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs

@ -39,6 +39,7 @@ namespace ICSharpCode.Decompiler @@ -39,6 +39,7 @@ namespace ICSharpCode.Decompiler
readonly string basePath;
readonly string targetFrameworkId;
readonly string version;
readonly string dotnetBasePath = FindDotNetExeDirectory();
public DotNetCorePathFinder(string parentAssemblyFileName, string targetFrameworkId, string version)
{
@ -101,9 +102,10 @@ namespace ICSharpCode.Decompiler @@ -101,9 +102,10 @@ namespace ICSharpCode.Decompiler
}
}
static string FallbackToDotNetSharedDirectory(AssemblyNameReference name, string version)
string FallbackToDotNetSharedDirectory(AssemblyNameReference name, string version)
{
var basePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "dotnet\\shared\\Microsoft.NETCore.App", version);
if (dotnetBasePath == null) return null;
var basePath = Path.Combine(dotnetBasePath, "shared\\Microsoft.NETCore.App", version);
DecompilerEventSource.Log.Info($"Fallback: use {basePath}");
if (File.Exists(Path.Combine(basePath, name.Name + ".dll"))) {
return Path.Combine(basePath, name.Name + ".dll");
@ -112,5 +114,24 @@ namespace ICSharpCode.Decompiler @@ -112,5 +114,24 @@ namespace ICSharpCode.Decompiler
}
return null;
}
static string FindDotNetExeDirectory()
{
char separator;
string dotnetExeName;
if (Environment.OSVersion.Platform == PlatformID.Unix) {
separator = ':';
dotnetExeName = "dotnet";
} else {
separator = ';';
dotnetExeName = "dotnet.exe";
}
foreach (var item in Environment.GetEnvironmentVariable("PATH").Split(separator)) {
var path = Environment.ExpandEnvironmentVariables(item);
if (File.Exists(Path.Combine(path, dotnetExeName)))
return path;
}
return null;
}
}
}

1
ILSpy/LoadedAssembly.cs

@ -291,6 +291,7 @@ namespace ICSharpCode.ILSpy @@ -291,6 +291,7 @@ namespace ICSharpCode.ILSpy
DecompilerEventSource.Log.Info($"Success - Loading {file}...");
return assemblyList.OpenAssembly(file, true);
} else {
DecompilerEventSource.Log.Info($"Warning - Failed to resolve {name.FullName}...");
return null;
}
}

Loading…
Cancel
Save