Skip to content

Commit

Permalink
Merge pull request #3265 from Herrmel/ignore_empty_dotnetcore_version…
Browse files Browse the repository at this point in the history
…_path

Ignore empty version directories of dotnet
  • Loading branch information
siegfriedpammer authored Aug 21, 2024
2 parents 58bd499 + 0330f38 commit dd04564
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -274,7 +277,7 @@ string RemoveTrailingVersionInfo()

try
{
return (new Version(RemoveTrailingVersionInfo()), name);
return (new Version(RemoveTrailingVersionInfo()), directory);
}
catch (Exception ex)
{
Expand Down
4 changes: 2 additions & 2 deletions ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() ?? ".";
}
Expand Down

0 comments on commit dd04564

Please sign in to comment.