From 63c2bb0b184d1213e28c9fb04155428c7c5bbbfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herrmannsd=C3=B6rfer=2C=20Felix?= Date: Mon, 19 Aug 2024 10:08:08 +0200 Subject: [PATCH 1/2] Ignore empty version directories of dotnet --- .../Metadata/DotNetCorePathFinder.cs | 11 ++++++----- .../Metadata/UniversalAssemblyResolver.cs | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs b/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs index 67f266c54c..a5dd8c2005 100644 --- a/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs +++ b/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs @@ -249,21 +249,22 @@ 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.directory.EnumerateFiles().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 +275,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() ?? "."; } From 0330f38c0642c457b58e5aa44c8436cb8cebb2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herrmannsd=C3=B6rfer=2C=20Felix?= Date: Wed, 21 Aug 2024 08:39:38 +0200 Subject: [PATCH 2/2] Include Subdirectories when checking for empty dotnet version directory --- ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs b/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs index a5dd8c2005..00a208674f 100644 --- a/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs +++ b/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs @@ -253,9 +253,11 @@ static string GetClosestVersionFolder(string basePath, Version version) .Where(v => v.version != null); foreach (var folder in foundVersions.OrderBy(v => v.version)) { - if (folder.version >= version) - if(folder.directory.EnumerateFiles().Any()) - return folder.directory.Name; + if (folder.version >= version + && folder.directory.EnumerateFiles("*.dll", SearchOption.AllDirectories).Any()) + { + return folder.directory.Name; + } } return version.ToString(); }