diff --git a/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs b/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs index 67f266c54c..00a208674f 100644 --- a/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs +++ b/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs @@ -249,21 +249,24 @@ public string TryResolveDotNetCoreShared(IAssemblyReference name, out string run static string GetClosestVersionFolder(string basePath, Version version) { var foundVersions = new DirectoryInfo(basePath).GetDirectories() - .Select(d => ConvertToVersion(d.Name)) + .Select(ConvertToVersion) .Where(v => v.version != null); foreach (var folder in foundVersions.OrderBy(v => v.version)) { - if (folder.version >= version) - return folder.directoryName; + if (folder.version >= version + && folder.directory.EnumerateFiles("*.dll", SearchOption.AllDirectories).Any()) + { + return folder.directory.Name; + } } return version.ToString(); } - internal static (Version version, string directoryName) ConvertToVersion(string name) + internal static (Version version, DirectoryInfo directory) ConvertToVersion(DirectoryInfo directory) { string RemoveTrailingVersionInfo() { - string shortName = name; + string shortName = directory.Name; int dashIndex = shortName.IndexOf('-'); if (dashIndex > 0) { @@ -274,7 +277,7 @@ string RemoveTrailingVersionInfo() try { - return (new Version(RemoveTrailingVersionInfo()), name); + return (new Version(RemoveTrailingVersionInfo()), directory); } catch (Exception ex) { diff --git a/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs b/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs index ff27d30d6a..90ba8724ac 100644 --- a/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs +++ b/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs @@ -386,11 +386,11 @@ DotNetCorePathFinder InitDotNetCorePathFinder() string FindClosestVersionDirectory(string basePath, Version? version) { string? path = null; - foreach (var folder in new DirectoryInfo(basePath).GetDirectories().Select(d => DotNetCorePathFinder.ConvertToVersion(d.Name)) + foreach (var folder in new DirectoryInfo(basePath).GetDirectories().Select(DotNetCorePathFinder.ConvertToVersion) .Where(v => v.Item1 != null).OrderByDescending(v => v.Item1)) { if (path == null || version == null || folder.Item1 >= version) - path = folder.Item2; + path = folder.Item2.Name; } return path ?? version?.ToString() ?? "."; }