Skip to content

Commit

Permalink
Merged PR 732978: Remove platform version when parsing NuGetFramework…
Browse files Browse the repository at this point in the history
… from TFM

- PlatformVersion is not well supported by the FrameworkCompatibilityService
 (see NuGet/NuGetGallery#9364 for details)

Related work items: #2092724
  • Loading branch information
JoeRobich authored and deivid-rodriguez committed Nov 15, 2023
1 parent 2303110 commit 178a3e4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace NuGetUpdater.Core.Test.FrameworkChecker;
public class CompatibilityCheckerFacts
{
[Theory]
[InlineData("net8.0", "net7.0")]
[InlineData("net7.0", "net7.0")]
[InlineData("net7.0", "net6.0")]
[InlineData("net7.0", "net5.0")]
Expand All @@ -26,6 +27,7 @@ public void PackageContainsCompatibleFramework(string projectTfm, string package
[Theory]
[InlineData("net48", "netcoreapp3.1")]
[InlineData("net48", "netstandard2.1")]
[InlineData("net7.0", "net8.0")]
[InlineData("net6.0", "net7.0")]
[InlineData("net5.0", "net6.0")]
[InlineData("netcoreapp3.1", "net5.0")]
Expand All @@ -42,6 +44,7 @@ public void PackageContainsIncompatibleFramework(string projectTfm, string packa
[Theory]
[InlineData(new[] { "net7.0", "net472" }, new[] { "netstandard2.0" })]
[InlineData(new[] { "net7.0", "net472" }, new[] { "net5.0", "net461" })]
[InlineData(new[] { "net6.0", "net6.0-windows10.0.19041" }, new[] { "net6.0", ".NETStandard2.0" })]
public void PackageContainsCompatibleFrameworks(string[] projectTfms, string[] packageTfms)
{
var result = CompatibilityChecker.IsCompatible(projectTfms, packageTfms, new Logger(verbose: true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class CompatibilityChecker
{
public static bool IsCompatible(string[] projectTfms, string[] packageTfms, Logger logger)
{
var projectFrameworks = projectTfms.Select(t => NuGetFramework.Parse(t));
var packageFrameworks = packageTfms.Select(t => NuGetFramework.Parse(t));
var projectFrameworks = projectTfms.Select(ParseFramework);
var packageFrameworks = packageTfms.Select(ParseFramework);

var compatibilityService = new FrameworkCompatibilityService();
var compatibleFrameworks = compatibilityService.GetCompatibleFrameworks(packageFrameworks);
Expand All @@ -23,5 +23,17 @@ public static bool IsCompatible(string[] projectTfms, string[] packageTfms, Logg

logger.Log("The package is compatible.");
return true;

static NuGetFramework ParseFramework(string tfm)
{
var framework = NuGetFramework.Parse(tfm);
if (framework.HasPlatform && framework.PlatformVersion != FrameworkConstants.EmptyVersion)
{
// Platform versions are not well supported by the FrameworkCompatibilityService. Make a best
// effort by including just the platform.
framework = new NuGetFramework(framework.Framework, framework.Version, framework.Platform, FrameworkConstants.EmptyVersion);
}
return framework;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace NuGetUpdater.Core.FrameworkChecker;
/// </remarks>
public static class SupportedFrameworks
{
public static readonly Version Version8 = new Version(8, 0, 0, 0);

public static readonly NuGetFramework MonoAndroid = new NuGetFramework(FrameworkIdentifiers.MonoAndroid, EmptyVersion);
public static readonly NuGetFramework MonoTouch = new NuGetFramework(FrameworkIdentifiers.MonoTouch, EmptyVersion);
public static readonly NuGetFramework MonoMac = new NuGetFramework(FrameworkIdentifiers.MonoMac, EmptyVersion);
Expand All @@ -44,6 +46,14 @@ public static class SupportedFrameworks
public static readonly NuGetFramework Net70Tizen = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version7, "tizen", EmptyVersion);
public static readonly NuGetFramework Net70TvOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version7, "tvos", EmptyVersion);
public static readonly NuGetFramework Net70Windows = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version7, "windows", EmptyVersion);
public static readonly NuGetFramework Net80 = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8);
public static readonly NuGetFramework Net80Android = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "android", EmptyVersion);
public static readonly NuGetFramework Net80Ios = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "ios", EmptyVersion);
public static readonly NuGetFramework Net80MacOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "macos", EmptyVersion);
public static readonly NuGetFramework Net80MacCatalyst = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "maccatalyst", EmptyVersion);
public static readonly NuGetFramework Net80Tizen = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "tizen", EmptyVersion);
public static readonly NuGetFramework Net80TvOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "tvos", EmptyVersion);
public static readonly NuGetFramework Net80Windows = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "windows", EmptyVersion);
public static readonly NuGetFramework NetCore = new NuGetFramework(FrameworkIdentifiers.NetCore, EmptyVersion);
public static readonly NuGetFramework NetMf = new NuGetFramework(FrameworkIdentifiers.NetMicro, EmptyVersion);
public static readonly NuGetFramework UAP = new NuGetFramework(FrameworkIdentifiers.UAP, EmptyVersion);
Expand All @@ -68,6 +78,7 @@ static SupportedFrameworks()
Net50, Net50Windows,
Net60, Net60Android, Net60Ios, Net60MacCatalyst, Net60MacOs, Net60TvOs, Net60Windows,
Net70, Net70Android, Net70Ios, Net70MacCatalyst, Net70MacOs, Net70TvOs, Net70Windows,
Net80, Net80Android, Net80Ios, Net80MacCatalyst, Net80MacOs, Net80TvOs, Net80Windows,
NetCore, NetCore45, NetCore451,
NetCoreApp10, NetCoreApp11, NetCoreApp20, NetCoreApp21, NetCoreApp22, NetCoreApp30, NetCoreApp31,
NetMf,
Expand All @@ -87,6 +98,7 @@ public static class TfmFilters
{
public static readonly List<NuGetFramework> NetTfms = new List<NuGetFramework>
{
Net80,
Net70,
Net60,
Net50
Expand Down

0 comments on commit 178a3e4

Please sign in to comment.