diff --git a/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs b/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs index 46bd8f09f..740ecc0d4 100644 --- a/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs +++ b/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs @@ -83,24 +83,35 @@ namespace ICSharpCode.Decompiler.Metadata } } + packageBasePaths.Add(basePath); + var depsJsonFileName = Path.Combine(basePath, $"{assemblyName}.deps.json"); - if (!File.Exists(depsJsonFileName)) { + if (File.Exists(depsJsonFileName)) { + packages = LoadPackageInfos(depsJsonFileName, targetFrameworkIdString).ToArray(); + + foreach (var path in LookupPaths) { + foreach (var p in packages) { + foreach (var item in p.RuntimeComponents) { + var itemPath = Path.GetDirectoryName(item); + var fullPath = Path.Combine(path, p.Name, p.Version, itemPath).ToLowerInvariant(); + if (Directory.Exists(fullPath)) + packageBasePaths.Add(fullPath); + } + } + } + } else { loadInfo?.AddMessage(assemblyName, MessageKind.Warning, $"{assemblyName}.deps.json could not be found!"); - return; } + } - packages = LoadPackageInfos(depsJsonFileName, targetFrameworkIdString).ToArray(); + public void AddSearchDirectory(string path) + { + this.packageBasePaths.Add(path); + } - foreach (var path in LookupPaths) { - foreach (var p in packages) { - foreach (var item in p.RuntimeComponents) { - var itemPath = Path.GetDirectoryName(item); - var fullPath = Path.Combine(path, p.Name, p.Version, itemPath).ToLowerInvariant(); - if (Directory.Exists(fullPath)) - packageBasePaths.Add(fullPath); - } - } - } + public void RemoveSearchDirectory(string path) + { + this.packageBasePaths.Remove(path); } public string TryResolveDotNetCore(IAssemblyReference name) diff --git a/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs b/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs index 8ccc7f237..22fc24105 100644 --- a/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs +++ b/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs @@ -71,11 +71,13 @@ namespace ICSharpCode.Decompiler.Metadata public void AddSearchDirectory(string directory) { directories.Add(directory); + dotNetCorePathFinder?.AddSearchDirectory(directory); } public void RemoveSearchDirectory(string directory) { directories.Remove(directory); + dotNetCorePathFinder?.RemoveSearchDirectory(directory); } public string[] GetSearchDirectories() @@ -185,6 +187,9 @@ namespace ICSharpCode.Decompiler.Metadata goto default; if (dotNetCorePathFinder == null) { dotNetCorePathFinder = new DotNetCorePathFinder(mainAssemblyFileName, targetFramework, targetFrameworkIdentifier, targetFrameworkVersion); + foreach (var directory in directories) { + dotNetCorePathFinder.AddSearchDirectory(directory); + } } file = dotNetCorePathFinder.TryResolveDotNetCore(name); if (file != null)