Skip to content

Commit

Permalink
Fix #3349: Get rid of version string manipulation in UniversalAssembl…
Browse files Browse the repository at this point in the history
…yResolver.ParseTargetFramework.
  • Loading branch information
siegfriedpammer committed Dec 13, 2024
1 parent e652490 commit 62cdf38
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System;

using ICSharpCode.Decompiler.CSharp.ProjectDecompiler;
using ICSharpCode.Decompiler.Metadata;

using NUnit.Framework;

Expand Down Expand Up @@ -119,5 +120,14 @@ public void VerifyMoniker(string identifier, int version, string expectedMoniker
// Assert
Assert.That(targetFramework.Moniker, Is.EqualTo(expectedMoniker));
}

[TestCase(".NETCoreApp, Version=v5.0", TargetFrameworkIdentifier.NET, "5.0.0")]
[TestCase(".NETCoreApp, Version=v10.0", TargetFrameworkIdentifier.NET, "10.0.0")]
public void VerifyUniversalAssemblyResolverParseTargetFramework(string targetFramework, TargetFrameworkIdentifier identifier, string version)
{
var (id, v) = UniversalAssemblyResolver.ParseTargetFramework(targetFramework);
Assert.That(id, Is.EqualTo(identifier));
Assert.That(v.ToString(3), Is.EqualTo(version));
}
}
}
15 changes: 8 additions & 7 deletions ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,16 @@ internal static (TargetFrameworkIdentifier, Version) ParseTargetFramework(string
switch (pair[0].Trim().ToUpperInvariant())
{
case "VERSION":
var versionString = pair[1].TrimStart('v', ' ', '\t');
if (identifier == TargetFrameworkIdentifier.NETCoreApp ||
identifier == TargetFrameworkIdentifier.NETStandard)
{
if (versionString.Length == 3)
versionString += ".0";
}
var versionString = pair[1].TrimStart('v', 'V', ' ', '\t');

if (!Version.TryParse(versionString, out version))
{
version = null;
}
else
{
version = new Version(version.Major, version.Minor, version.Build < 0 ? 0 : version.Build);
}
// .NET 5 or greater still use ".NETCOREAPP" as TargetFrameworkAttribute value...
if (version?.Major >= 5 && identifier == TargetFrameworkIdentifier.NETCoreApp)
identifier = TargetFrameworkIdentifier.NET;
Expand Down

0 comments on commit 62cdf38

Please sign in to comment.