diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs index 585fc988df1..f4e09609f70 100644 --- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs +++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/LockFileBuilder.cs @@ -174,7 +174,7 @@ public LockFile CreateLockFile(LockFile previousLockFile, // Check if warnings should be displayed for the current framework. var tfi = project.GetTargetFramework(targetGraph.Framework); - var warnForImportsOnGraph = tfi.Warn + bool warnForImportsOnGraph = tfi.Warn && (target.TargetFramework is FallbackFramework || target.TargetFramework is AssetTargetFallbackFramework); @@ -398,4 +398,4 @@ private static bool HasTools(string file) return file.StartsWith("tools/", StringComparison.OrdinalIgnoreCase); } } -} \ No newline at end of file +} diff --git a/src/NuGet.Core/NuGet.Frameworks/CompatibilityProvider.cs b/src/NuGet.Core/NuGet.Frameworks/CompatibilityProvider.cs index 35b196e9f37..6a9ff3c09a7 100644 --- a/src/NuGet.Core/NuGet.Frameworks/CompatibilityProvider.cs +++ b/src/NuGet.Core/NuGet.Frameworks/CompatibilityProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -17,7 +17,7 @@ class CompatibilityProvider : IFrameworkCompatibilityProvider { private readonly IFrameworkNameProvider _mappings; private readonly FrameworkExpander _expander; - private static readonly NuGetFrameworkFullComparer _fullComparer = new NuGetFrameworkFullComparer(); + private static readonly NuGetFrameworkFullComparer FullComparer = new NuGetFrameworkFullComparer(); private readonly ConcurrentDictionary _cache; public CompatibilityProvider(IFrameworkNameProvider mappings) @@ -62,7 +62,7 @@ public bool IsCompatible(NuGetFramework target, NuGetFramework candidate) bool? result = null; // check if they are the exact same - if (_fullComparer.Equals(target, candidate)) + if (FullComparer.Equals(target, candidate)) { return true; } @@ -181,10 +181,18 @@ private bool IsCompatibleWithTarget(NuGetFramework target, NuGetFramework candid private static bool IsCompatibleWithTargetCore(NuGetFramework target, NuGetFramework candidate) { - // compare the frameworks - return (NuGetFramework.FrameworkNameComparer.Equals(target, candidate) - && StringComparer.OrdinalIgnoreCase.Equals(target.Profile, candidate.Profile) - && IsVersionCompatible(target.Version, candidate.Version)); + if (target.IsNet5Era) + { + return NuGetFramework.FrameworkNameComparer.Equals(target, candidate) + && IsVersionCompatible(target.Version, candidate.Version) + && (!candidate.HasProfile || StringComparer.OrdinalIgnoreCase.Equals(target.Profile, candidate.Profile)); + } + else + { + return NuGetFramework.FrameworkNameComparer.Equals(target, candidate) + && IsVersionCompatible(target.Version, candidate.Version) + && StringComparer.OrdinalIgnoreCase.Equals(target.Profile, candidate.Profile); + } } private static bool IsVersionCompatible(Version target, Version candidate) diff --git a/src/NuGet.Core/NuGet.Frameworks/FrameworkConstants.cs b/src/NuGet.Core/NuGet.Frameworks/FrameworkConstants.cs index 55d665b0acb..4375a402675 100644 --- a/src/NuGet.Core/NuGet.Frameworks/FrameworkConstants.cs +++ b/src/NuGet.Core/NuGet.Frameworks/FrameworkConstants.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; namespace NuGet.Frameworks { @@ -13,7 +14,7 @@ namespace NuGet.Frameworks static class FrameworkConstants { public static readonly Version EmptyVersion = new Version(0, 0, 0, 0); - public static readonly Version MaxVersion = new Version(Int32.MaxValue, 0, 0, 0); + public static readonly Version MaxVersion = new Version(int.MaxValue, 0, 0, 0); public static readonly Version Version5 = new Version(5, 0, 0, 0); public static readonly Version Version10 = new Version(10, 0, 0, 0); public static readonly FrameworkRange DotNetAll = new FrameworkRange( @@ -33,6 +34,13 @@ public static class PlatformIdentifiers public const string Windows = "Windows"; } + /// + /// Allowed list of profiles in Net5.0ERA + /// + internal static HashSet FrameworkProfiles + = new HashSet(StringComparer.OrdinalIgnoreCase) + { }; + public static class FrameworkIdentifiers { public const string NetCoreApp = ".NETCoreApp"; @@ -180,6 +188,10 @@ public static readonly NuGetFramework NetCoreApp22 public static readonly NuGetFramework NetCoreApp30 = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, new Version(3, 0, 0, 0)); public static readonly NuGetFramework NetCoreApp31 - = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, new Version(3, 1, 0, 0)); } + = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, new Version(3, 1, 0, 0)); + + // .NET 5.0 and later has NetCoreApp identifier + public static readonly NuGetFramework Net50 = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version5); + } } } diff --git a/src/NuGet.Core/NuGet.Frameworks/FrameworkNameProvider.cs b/src/NuGet.Core/NuGet.Frameworks/FrameworkNameProvider.cs index 02037c1951f..9d902fa0436 100644 --- a/src/NuGet.Core/NuGet.Frameworks/FrameworkNameProvider.cs +++ b/src/NuGet.Core/NuGet.Frameworks/FrameworkNameProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -138,7 +138,7 @@ public bool TryGetVersion(string versionString, out Version version) { version = null; - if (String.IsNullOrEmpty(versionString)) + if (string.IsNullOrEmpty(versionString)) { version = new Version(0, 0); } @@ -160,7 +160,7 @@ public bool TryGetVersion(string versionString, out Version version) // take only the first 4 digits and add dots // 451 -> 4.5.1 // 81233 -> 8123 - return Version.TryParse(String.Join(".", versionString.ToCharArray().Take(4)), out version); + return Version.TryParse(string.Join(".", versionString.ToCharArray().Take(4)), out version); } } @@ -185,7 +185,7 @@ public string GetVersionString(string framework, Version version) versionParts.Push(version.Revision > 0 ? version.Revision : 0); // By default require the version to have 2 digits, for legacy frameworks 1 is allowed - var minPartCount = _singleDigitVersionFrameworks.Contains(framework) ? 1 : 2; + var minPartCount = SingleDigitVersionFrameworks.Contains(framework) ? 1 : 2; // remove all trailing zeros beyond the minor version while ((versionParts.Count > minPartCount @@ -198,20 +198,12 @@ public string GetVersionString(string framework, Version version) // netcoreapp, or if any parts of the version are over 9 we need to use decimals if (string.Equals( framework, - FrameworkConstants.FrameworkIdentifiers.NetPlatform, + FrameworkConstants.FrameworkIdentifiers.NetCoreApp, StringComparison.OrdinalIgnoreCase) || string.Equals( framework, FrameworkConstants.FrameworkIdentifiers.NetStandard, StringComparison.OrdinalIgnoreCase) - || string.Equals( - framework, - FrameworkConstants.FrameworkIdentifiers.NetStandardApp, - StringComparison.OrdinalIgnoreCase) - || string.Equals( - framework, - FrameworkConstants.FrameworkIdentifiers.NetCoreApp, - StringComparison.OrdinalIgnoreCase) || versionParts.Any(x => x > 9)) { // An additional zero is needed for decimals @@ -232,7 +224,7 @@ public string GetVersionString(string framework, Version version) } // Legacy frameworks that are allowed to have a single digit for the version number - private static readonly HashSet _singleDigitVersionFrameworks = new HashSet( + private static readonly HashSet SingleDigitVersionFrameworks = new HashSet( new string[] { FrameworkConstants.FrameworkIdentifiers.Windows, FrameworkConstants.FrameworkIdentifiers.WindowsPhone, @@ -502,7 +494,7 @@ public bool TryGetPortableProfileNumber(string profile, out int profileNumber) if (profile.StartsWith("Profile", StringComparison.OrdinalIgnoreCase)) { var trimmed = profile.Substring(7, profile.Length - 7); - return Int32.TryParse(trimmed, out profileNumber); + return int.TryParse(trimmed, out profileNumber); } profileNumber = -1; diff --git a/src/NuGet.Core/NuGet.Frameworks/NuGetFramework.cs b/src/NuGet.Core/NuGet.Frameworks/NuGetFramework.cs index 8c151fdb437..2354726b1cc 100644 --- a/src/NuGet.Core/NuGet.Frameworks/NuGetFramework.cs +++ b/src/NuGet.Core/NuGet.Frameworks/NuGetFramework.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -23,7 +23,7 @@ partial class NuGetFramework : IEquatable private readonly string _frameworkIdentifier; private readonly Version _frameworkVersion; private readonly string _frameworkProfile; - private const string _portable = "portable"; + private const string Portable = "portable"; private int? _hashCode; public NuGetFramework(NuGetFramework framework) @@ -41,6 +41,8 @@ public NuGetFramework(string framework, Version version) { } + private const int Version5 = 5; + public NuGetFramework(string frameworkIdentifier, Version frameworkVersion, string frameworkProfile) { if (frameworkIdentifier == null) @@ -56,6 +58,7 @@ public NuGetFramework(string frameworkIdentifier, Version frameworkVersion, stri _frameworkIdentifier = frameworkIdentifier; _frameworkVersion = NormalizeVersion(frameworkVersion); _frameworkProfile = frameworkProfile ?? string.Empty; + IsNet5Era = (_frameworkVersion.Major >= Version5 && StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.NetCoreApp, _frameworkIdentifier)); } /// @@ -79,7 +82,7 @@ public Version Version /// public bool HasProfile { - get { return !String.IsNullOrEmpty(Profile); } + get { return !string.IsNullOrEmpty(Profile); } } /// @@ -113,20 +116,20 @@ public string GetDotNetFrameworkName(IFrameworkNameProvider mappings) if (framework.IsSpecificFramework) { - var parts = new List(3) { framework.Framework }; + var parts = new List(3) { Framework }; - parts.Add(String.Format(CultureInfo.InvariantCulture, "Version=v{0}", GetDisplayVersion(framework.Version))); + parts.Add(string.Format(CultureInfo.InvariantCulture, "Version=v{0}", GetDisplayVersion(framework.Version))); - if (!String.IsNullOrEmpty(framework.Profile)) + if (!string.IsNullOrEmpty(framework.Profile)) { - parts.Add(String.Format(CultureInfo.InvariantCulture, "Profile={0}", framework.Profile)); + parts.Add(string.Format(CultureInfo.InvariantCulture, "Profile={0}", framework.Profile)); } - result = String.Join(",", parts); + result = string.Join(",", parts); } else { - result = String.Format(CultureInfo.InvariantCulture, "{0},Version=v0.0", framework.Framework); + result = string.Format(CultureInfo.InvariantCulture, "{0},Version=v0.0", framework.Framework); } return result; @@ -141,6 +144,14 @@ public string GetShortFolderName() return GetShortFolderName(DefaultFrameworkNameProvider.Instance); } + /// + /// Helper that is .NET 5 Era aware to replace identifier when appropriate + /// + private string GetFrameworkIdentifier() + { + return IsNet5Era ? FrameworkConstants.FrameworkIdentifiers.Net : Framework; + } + /// /// Creates the shortened version of the framework using the given mappings. /// @@ -156,12 +167,14 @@ public virtual string GetShortFolderName(IFrameworkNameProvider mappings) var shortFramework = string.Empty; // get the framework - if (!mappings.TryGetShortIdentifier(framework.Framework, out shortFramework)) + if (!mappings.TryGetShortIdentifier( + GetFrameworkIdentifier(), + out shortFramework)) { shortFramework = GetLettersAndDigitsOnly(framework.Framework); } - if (String.IsNullOrEmpty(shortFramework)) + if (string.IsNullOrEmpty(shortFramework)) { throw new FrameworkException(string.Format( CultureInfo.CurrentCulture, @@ -195,7 +208,7 @@ public virtual string GetShortFolderName(IFrameworkNameProvider mappings) // sort the PCL frameworks by alphabetical order var sortedFrameworks = required.Select(e => e.GetShortFolderName(mappings)).OrderBy(e => e, StringComparer.OrdinalIgnoreCase).ToList(); - sb.Append(String.Join("+", sortedFrameworks)); + sb.Append(string.Join("+", sortedFrameworks)); } else { @@ -216,7 +229,7 @@ public virtual string GetShortFolderName(IFrameworkNameProvider mappings) shortProfile = framework.Profile; } - if (!String.IsNullOrEmpty(shortProfile)) + if (!string.IsNullOrEmpty(shortProfile)) { sb.Append("-"); sb.Append(shortProfile); @@ -234,7 +247,7 @@ public virtual string GetShortFolderName(IFrameworkNameProvider mappings) private static string GetDisplayVersion(Version version) { - var sb = new StringBuilder(String.Format(CultureInfo.InvariantCulture, "{0}.{1}", version.Major, version.Minor)); + var sb = new StringBuilder(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", version.Major, version.Minor)); if (version.Build > 0 || version.Revision > 0) @@ -256,7 +269,7 @@ private static string GetLettersAndDigitsOnly(string s) foreach (var c in s.ToCharArray()) { - if (Char.IsLetterOrDigit(c)) + if (char.IsLetterOrDigit(c)) { sb.Append(c); } @@ -282,7 +295,7 @@ public bool IsPackageBased get { // For these frameworks all versions are packages based. - if (_packagesBased.Contains(Framework)) + if (PackagesBased.Contains(Framework)) { return true; } @@ -334,6 +347,11 @@ public bool IsSpecificFramework get { return !IsAgnostic && !IsAny && !IsUnsupported; } } + /// + /// True if this framework is Net5 or later, until we invent something new. + /// + internal bool IsNet5Era { get; set; } + /// /// Full framework comparison of the identifier, version, profile, platform, and platform version /// @@ -408,7 +426,7 @@ private static Version NormalizeVersion(Version version) /// /// Frameworks that are packages based across all versions. /// - private static readonly SortedSet _packagesBased = new SortedSet( + private static readonly SortedSet PackagesBased = new SortedSet( new[] { FrameworkConstants.FrameworkIdentifiers.DnxCore, diff --git a/src/NuGet.Core/NuGet.Frameworks/NuGetFrameworkFactory.cs b/src/NuGet.Core/NuGet.Frameworks/NuGetFrameworkFactory.cs index 39ac2d2f165..6f1bf93696a 100644 --- a/src/NuGet.Core/NuGet.Frameworks/NuGetFrameworkFactory.cs +++ b/src/NuGet.Core/NuGet.Frameworks/NuGetFrameworkFactory.cs @@ -104,7 +104,7 @@ public static NuGetFramework ParseFrameworkName(string frameworkName, IFramework var versionPart = SingleOrDefaultSafe(parts.Where(s => s.IndexOf("Version=", StringComparison.OrdinalIgnoreCase) == 0)); var profilePart = SingleOrDefaultSafe(parts.Where(s => s.IndexOf("Profile=", StringComparison.OrdinalIgnoreCase) == 0)); - if (!String.IsNullOrEmpty(versionPart)) + if (!string.IsNullOrEmpty(versionPart)) { var versionString = versionPart.Split('=')[1].TrimStart('v'); @@ -122,7 +122,7 @@ public static NuGetFramework ParseFrameworkName(string frameworkName, IFramework } } - if (!String.IsNullOrEmpty(profilePart)) + if (!string.IsNullOrEmpty(profilePart)) { profile = profilePart.Split('=')[1]; } @@ -196,37 +196,62 @@ public static NuGetFramework ParseFolder(string folderName, IFrameworkNameProvid || mappings.TryGetVersion(parts.Item2, out version)) { var profileShort = parts.Item3; - string profile = null; - if (!mappings.TryGetProfile(framework, profileShort, out profile)) + + if (version.Major >= 5 + && StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.Net, framework)) { - profile = profileShort ?? string.Empty; + // net should be treated as netcoreapp in 5.0 and later + framework = FrameworkConstants.FrameworkIdentifiers.NetCoreApp; + if (!string.IsNullOrEmpty(profileShort)) + { + bool validProfile = FrameworkConstants.FrameworkProfiles.Contains(profileShort); + if (validProfile) + { + result = new NuGetFramework(framework, version, profileShort.ToLower()); + } + else + { + return result; // with result == UnsupportedFramework + } + } + else + { + result = new NuGetFramework(framework, version, string.Empty); + } } - - if (StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.Portable, framework)) + else { - IEnumerable clientFrameworks = null; - if (!mappings.TryGetPortableFrameworks(profileShort, out clientFrameworks)) + string profile = null; + if (!mappings.TryGetProfile(framework, profileShort, out profile)) { - result = UnsupportedFramework; + profile = profileShort ?? string.Empty; } - else + + if (StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.Portable, framework)) { - var profileNumber = -1; - if (mappings.TryGetPortableProfile(clientFrameworks, out profileNumber)) + IEnumerable clientFrameworks = null; + if (!mappings.TryGetPortableFrameworks(profileShort, out clientFrameworks)) { - var portableProfileNumber = FrameworkNameHelpers.GetPortableProfileNumberString(profileNumber); - result = new NuGetFramework(framework, version, portableProfileNumber); + result = UnsupportedFramework; } else { - // TODO: should this be unsupported? - result = new NuGetFramework(framework, version, profileShort); + var profileNumber = -1; + if (mappings.TryGetPortableProfile(clientFrameworks, out profileNumber)) + { + var portableProfileNumber = FrameworkNameHelpers.GetPortableProfileNumberString(profileNumber); + result = new NuGetFramework(framework, version, portableProfileNumber); + } + else + { + result = new NuGetFramework(framework, version, profileShort); + } } } - } - else - { - result = new NuGetFramework(framework, version, profile); + else + { + result = new NuGetFramework(framework, version, profile); + } } } } @@ -415,31 +440,6 @@ private static bool TryParseCommonFramework(string frameworkString, out NuGetFra case "dotnet5.0": framework = FrameworkConstants.CommonFrameworks.DotNet50; break; - case "dotnet5.1": - framework = FrameworkConstants.CommonFrameworks.DotNet51; - break; - case "dotnet5.2": - framework = FrameworkConstants.CommonFrameworks.DotNet52; - break; - case "dotnet5.3": - framework = FrameworkConstants.CommonFrameworks.DotNet53; - break; - case "dotnet5.4": - framework = FrameworkConstants.CommonFrameworks.DotNet54; - break; - case "dotnet5.5": - framework = FrameworkConstants.CommonFrameworks.DotNet55; - break; - case "dotnet5.6": - framework = FrameworkConstants.CommonFrameworks.DotNet56; - break; - case "dnx451": - framework = FrameworkConstants.CommonFrameworks.Dnx451; - break; - case "dnxcore50": - case "dnxcore": - framework = FrameworkConstants.CommonFrameworks.DnxCore50; - break; case "net40": case "net4": framework = FrameworkConstants.CommonFrameworks.Net4; @@ -508,21 +508,19 @@ private static bool TryParseCommonFramework(string frameworkString, out NuGetFra case "netstandard21": framework = FrameworkConstants.CommonFrameworks.NetStandard21; break; - case "netstandardapp1.5": - case "netstandardapp15": - framework = FrameworkConstants.CommonFrameworks.NetStandardApp15; - break; - case "netcoreapp1.0": - case "netcoreapp10": - framework = FrameworkConstants.CommonFrameworks.NetCoreApp10; + case "netcoreapp2.1": + case "netcoreapp21": + framework = FrameworkConstants.CommonFrameworks.NetCoreApp21; break; - case "netcoreapp2.0": - case "netcoreapp20": - framework = FrameworkConstants.CommonFrameworks.NetCoreApp20; + case "netcoreapp3.1": + case "netcoreapp31": + framework = FrameworkConstants.CommonFrameworks.NetCoreApp31; break; - case "netcoreapp3.0": - case "netcoreapp30": - framework = FrameworkConstants.CommonFrameworks.NetCoreApp30; + case "netcoreapp5.0": + case "netcoreapp50": + case "net5.0": + case "net50": + framework = FrameworkConstants.CommonFrameworks.Net50; break; } diff --git a/src/NuGet.Core/NuGet.Frameworks/comparers/NuGetFrameworkFullComparer.cs b/src/NuGet.Core/NuGet.Frameworks/comparers/NuGetFrameworkFullComparer.cs index 9a0adc7d748..29204626880 100644 --- a/src/NuGet.Core/NuGet.Frameworks/comparers/NuGetFrameworkFullComparer.cs +++ b/src/NuGet.Core/NuGet.Frameworks/comparers/NuGetFrameworkFullComparer.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -32,7 +32,8 @@ public bool Equals(NuGetFramework x, NuGetFramework y) return x.Version == y.Version && StringComparer.OrdinalIgnoreCase.Equals(x.Framework, y.Framework) - && StringComparer.OrdinalIgnoreCase.Equals(x.Profile, y.Profile); + && StringComparer.OrdinalIgnoreCase.Equals(x.Profile, y.Profile) + && !x.IsUnsupported; } public int GetHashCode(NuGetFramework obj) diff --git a/test/NuGet.Clients.Tests/NuGet.SolutionRestoreManager.Test/VsSolutionRestoreServiceTests.cs b/test/NuGet.Clients.Tests/NuGet.SolutionRestoreManager.Test/VsSolutionRestoreServiceTests.cs index 71f6bd9ab8a..d160a12edf1 100644 --- a/test/NuGet.Clients.Tests/NuGet.SolutionRestoreManager.Test/VsSolutionRestoreServiceTests.cs +++ b/test/NuGet.Clients.Tests/NuGet.SolutionRestoreManager.Test/VsSolutionRestoreServiceTests.cs @@ -374,7 +374,7 @@ await CaptureNominateResultAsync(projectFullPath, cps.ProjectRestoreInfo2) : var actualTfi = actualProjectSpec.TargetFrameworks.Single(); var actualImports = string.Join(";", actualTfi.Imports.Select(x => x.GetShortFolderName())); - Assert.Equal("dotnet5.3;portable-net452+win81", actualImports); + Assert.Equal("dotnet53;portable-net452+win81", actualImports); } [Theory] diff --git a/test/NuGet.Core.Tests/NuGet.Frameworks.Test/CompatibilityTableTests.cs b/test/NuGet.Core.Tests/NuGet.Frameworks.Test/CompatibilityTableTests.cs index a85791ca630..b88abb975dc 100644 --- a/test/NuGet.Core.Tests/NuGet.Frameworks.Test/CompatibilityTableTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Frameworks.Test/CompatibilityTableTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; @@ -125,7 +125,7 @@ public void CompatibilityTable_NearestFound() [Fact] public void CompatibilityTable_NearestSingle() { - var net50 = NuGetFramework.Parse("net50"); + var net49 = NuGetFramework.Parse("net49"); var net35 = NuGetFramework.Parse("net35"); var net45 = NuGetFramework.Parse("net45"); var net40 = NuGetFramework.Parse("net40"); @@ -134,7 +134,7 @@ public void CompatibilityTable_NearestSingle() CompatibilityTable table = new CompatibilityTable(all); - Assert.Equal(net45, table.GetNearest(net50).Single()); + Assert.Equal(net45, table.GetNearest(net49).Single()); Assert.Null(table.GetNearest(net35).SingleOrDefault()); } } diff --git a/test/NuGet.Core.Tests/NuGet.Frameworks.Test/CompatibilityTests.cs b/test/NuGet.Core.Tests/NuGet.Frameworks.Test/CompatibilityTests.cs index 7b5f0bf7dc6..8d8b400c684 100644 --- a/test/NuGet.Core.Tests/NuGet.Frameworks.Test/CompatibilityTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Frameworks.Test/CompatibilityTests.cs @@ -9,6 +9,53 @@ namespace NuGet.Test public class CompatibilityTests { [Theory] + // net5.0 and later is not compat with net1.0 through net 4.x.xxx. + // users must use those TFMs via AssetTargetFallback, which will be set + [InlineData("net5.0", "net452", false)] + [InlineData("net5.0", "net462", false)] + [InlineData("net5.0", "net472", false)] + [InlineData("net5.0", "net482", false)] + [InlineData("net50", "net5.0", true)] + [InlineData("net5.0", "net50", true)] + + // netcoreapp 5.0 and later are still valid for now + [InlineData("netcoreapp5.0", "netcoreapp5.0", true)] + [InlineData("net5.0", "netcoreapp5.0", true)] + [InlineData("netcoreapp6.0", "netcoreapp5.0", true)] + + // net5.0 is compat with netstandard 1 through 2.1 + [InlineData("net5.0", "netstandard2.2", false)] + [InlineData("net5.0", "netstandard2.1", true)] + [InlineData("net5.0", "netstandard2.0", true)] + [InlineData("net5.0", "netstandard1.7", true)] + [InlineData("net5.0", "netstandard1.6", true)] + [InlineData("net5.0", "netstandard1.5", true)] + [InlineData("net5.0", "netstandard1.4", true)] + [InlineData("net5.0", "netstandard1.3", true)] + [InlineData("net5.0", "netstandard1.2", true)] + [InlineData("net5.0", "netstandard1.1", true)] + [InlineData("net5.0", "netstandard1.0", true)] + + // net5.0 and later is compat with netcoreapp3.1 + [InlineData("net4.9", "netcoreapp3.1", false)] + [InlineData("net5.0", "netcoreapp3.1", true)] + [InlineData("net5.1", "netcoreapp3.1", true)] + [InlineData("net6.0", "netcoreapp3.1", true)] + + // net5.0- is not supported yet + [InlineData("net5.0-android", "net5.0", false)] + [InlineData("net5.0-android", "netcoreapp3.1", false)] + [InlineData("net5.0-ios", "net5.0", false)] + [InlineData("net5.0-macos", "net5.0", false)] + [InlineData("net5.0-tvos", "net5.0", false)] + [InlineData("net5.0-watchos", "net5.0", false)] + [InlineData("net5.0-windows", "net5.0", false)] + [InlineData("net5.0", "net5.0-windows", false)] + + // net5.0 profile names cannot be made up. they will not be compat with anything. profile name will be changed to "Unsupported". + [InlineData("net5.0-madeupname", "net5.0", false)] + [InlineData("net5.0", "net5.0-madeupname", false)] + // dotnet [InlineData("dotnet", "dotnet", true)] [InlineData("dotnet5.1", "dotnet", true)] @@ -892,7 +939,7 @@ public void Compatibility_ProjectCannotInstallGenerationLibraries(string framewo [InlineData("net45")] [InlineData("net45-client")] [InlineData("net451")] - [InlineData("net50")] + [InlineData("net49")] [InlineData("net46")] [InlineData("dnx46")] [InlineData("dnx50")] diff --git a/test/NuGet.Core.Tests/NuGet.Frameworks.Test/FrameworkReducerTests.cs b/test/NuGet.Core.Tests/NuGet.Frameworks.Test/FrameworkReducerTests.cs index 7e73308e4e5..ee4ab84a21a 100644 --- a/test/NuGet.Core.Tests/NuGet.Frameworks.Test/FrameworkReducerTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Frameworks.Test/FrameworkReducerTests.cs @@ -58,7 +58,7 @@ public class FrameworkReducerTests [InlineData("net461", "dotnet,portable-net45+win8,portable-net45+win8+wpa81", "dotnet")] [InlineData("net461", "portable-net45+win8,portable-net45+win8+wpa81", "portable-net45+win8")] [InlineData("net461", "portable-net45+win8+wpa81,native", "portable-net45+win8+wpa81")] - [InlineData("net7", "dotnet6.0,dotnet5.6,dotnet5.5,dotnet5.4,portable-net45+win8", "dotnet5.6")] + [InlineData("net49", "dotnet6.0,dotnet5.6,dotnet5.5,dotnet5.4,portable-net45+win8", "dotnet5.6")] // netstandard [InlineData("netstandard1.5", "net4,netstandard7.0,netstandard1.4", "netstandard1.4")] [InlineData("netstandard1.5", "net4,netstandard7.0,netstandard1.5", "netstandard1.5")] diff --git a/test/NuGet.Core.Tests/NuGet.Frameworks.Test/NuGetFrameworkParseTests.cs b/test/NuGet.Core.Tests/NuGet.Frameworks.Test/NuGetFrameworkParseTests.cs index 23943f607d4..52dd684d95c 100644 --- a/test/NuGet.Core.Tests/NuGet.Frameworks.Test/NuGetFrameworkParseTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Frameworks.Test/NuGetFrameworkParseTests.cs @@ -198,24 +198,18 @@ public void NuGetFramework_ProfileName(string folder, string expected) [Theory] [InlineData("net45", ".NETFramework,Version=v4.5")] + [InlineData("net10", ".NETFramework,Version=v1.0")] [InlineData("net20", ".NETFramework,Version=v2.0")] [InlineData("net40", ".NETFramework,Version=v4.0")] [InlineData("net35", ".NETFramework,Version=v3.5")] [InlineData("net40-client", ".NETFramework,Version=v4.0,Profile=Client")] [InlineData("net", ".NETFramework,Version=v0.0")] [InlineData("net10.1.2.3", ".NETFramework,Version=v10.1.2.3")] + [InlineData("net10.0", ".NETFramework,Version=v10.0")] [InlineData("net45-cf", ".NETFramework,Version=v4.5,Profile=CompactFramework")] [InlineData("uap10.0", "UAP,Version=v10.0")] [InlineData("dotnet", ".NETPlatform,Version=v0.0")] [InlineData("dotnet", ".NETPlatform,Version=v5.0")] - [InlineData("dotnet1.0", ".NETPlatform,Version=v1.0")] - [InlineData("dotnet5.1", ".NETPlatform,Version=v5.1")] - [InlineData("dotnet5.2", ".NETPlatform,Version=v5.2")] - [InlineData("dotnet5.3", ".NETPlatform,Version=v5.3")] - [InlineData("dotnet5.4", ".NETPlatform,Version=v5.4")] - [InlineData("dotnet5.5", ".NETPlatform,Version=v5.5")] - [InlineData("dotnet6.0", ".NETPlatform,Version=v6.0")] - [InlineData("dotnet6.0", ".NETPlatform,Version=v6")] [InlineData("netstandard", ".NETStandard,Version=v0.0")] [InlineData("netstandard1.0", ".NETStandard,Version=v1.0")] [InlineData("netstandard1.0", ".NETStandard,Version=v1.0.0")] @@ -225,11 +219,6 @@ public void NuGetFramework_ProfileName(string folder, string expected) [InlineData("netstandard1.3", ".NETStandard,Version=v1.3")] [InlineData("netstandard1.4", ".NETStandard,Version=v1.4")] [InlineData("netstandard1.5", ".NETStandard,Version=v1.5")] - [InlineData("netstandardapp", ".NETStandardApp,Version=v0.0")] - [InlineData("netstandardapp1.0", ".NETStandardApp,Version=v1.0")] - [InlineData("netstandardapp1.5", ".NETStandardApp,Version=v1.5")] - [InlineData("netstandardapp2.0", ".NETStandardApp,Version=v2.0")] - [InlineData("netstandardapp2.1", ".NETStandardApp,Version=v2.1")] [InlineData("netcoreapp", ".NETCoreApp,Version=v0.0")] [InlineData("netcoreapp1.0", ".NETCoreApp,Version=v1.0")] [InlineData("netcoreapp1.5", ".NETCoreApp,Version=v1.5")] @@ -248,6 +237,12 @@ public void NuGetFramework_ParseToShortName(string expected, string fullName) } [Theory] + // Net5.0 ERA + [InlineData("net5.0", ".NETCoreApp,Version=v5.0")] + [InlineData("net10.1.2.3", ".NETCoreApp,Version=v10.1.2.3")] + [InlineData("netcoreapp5.0", ".NETCoreApp,Version=v5.0")] + + // Pre-Net5.0 ERA [InlineData("net45", ".NETFramework,Version=v4.5")] [InlineData("net20", ".NETFramework,Version=v2.0")] [InlineData("net40", ".NETFramework,Version=v4.0")] @@ -255,7 +250,6 @@ public void NuGetFramework_ParseToShortName(string expected, string fullName) [InlineData("net40-full", ".NETFramework,Version=v4.0")] [InlineData("net40-client", ".NETFramework,Version=v4.0,Profile=Client")] [InlineData("net", ".NETFramework,Version=v0.0")] - [InlineData("net10.1.2.3", ".NETFramework,Version=v10.1.2.3")] [InlineData("net45-cf", ".NETFramework,Version=v4.5,Profile=CompactFramework")] [InlineData("uap10.0", "UAP,Version=v10.0")] [InlineData("dotnet", ".NETPlatform,Version=v5.0")] @@ -344,26 +338,6 @@ public void NuGetFramework_PortableWithInnerPortableProfileFails(string framewor } [Theory] - [InlineData("dotnet", "dotnet")] - [InlineData("dotnet", "dotnet50")] - [InlineData("dotnet", "dotnet5.0")] - [InlineData("dotnet50", "dotnet")] - [InlineData("dotnet50", "dotnet50")] - [InlineData("dotnet50", "dotnet5.0")] - [InlineData("dotnet5.0", "dotnet")] - [InlineData("dotnet5.0", "dotnet50")] - [InlineData("dotnet5.0", "dotnet5.0")] - [InlineData("dotnet5.1", "dotnet5.1")] - [InlineData("dotnet5.2", "dotnet5.2")] - [InlineData("dotnet5.3", "dotnet5.3")] - [InlineData("dotnet5.4", "dotnet5.4")] - [InlineData("dotnet5.5", "dotnet5.5")] - [InlineData("dotnet5.6", "dotnet5.6")] - [InlineData("dnx451", "dnx451")] - [InlineData("dnxcore50", "dnxcore50")] - [InlineData("dnxcore50", "dnxcore")] - [InlineData("dnxcore", "dnxcore50")] - [InlineData("dnxcore", "dnxcore")] [InlineData("net40", "net4")] [InlineData("net40", "net40")] [InlineData("net4", "net40")] @@ -415,22 +389,14 @@ public void NuGetFramework_PortableWithInnerPortableProfileFails(string framewor [InlineData("netstandard2.1", "netstandard21")] [InlineData("netstandard21", "netstandard2.1")] [InlineData("netstandard21", "netstandard21")] - [InlineData("netstandardapp1.5", "netstandardapp1.5")] - [InlineData("netstandardapp1.5", "netstandardapp15")] - [InlineData("netstandardapp15", "netstandardapp1.5")] - [InlineData("netstandardapp15", "netstandardapp15")] - [InlineData("netcoreapp1.0", "netcoreapp1.0")] - [InlineData("netcoreapp1.0", "netcoreapp10")] - [InlineData("netcoreapp10", "netcoreapp1.0")] - [InlineData("netcoreapp10", "netcoreapp10")] - [InlineData("netcoreapp2.0", "netcoreapp2.0")] - [InlineData("netcoreapp2.0", "netcoreapp20")] - [InlineData("netcoreapp20", "netcoreapp2.0")] - [InlineData("netcoreapp20", "netcoreapp20")] - [InlineData("netcoreapp3.0", "netcoreapp3.0")] - [InlineData("netcoreapp3.0", "netcoreapp30")] - [InlineData("netcoreapp30", "netcoreapp3.0")] - [InlineData("netcoreapp30", "netcoreapp30")] + [InlineData("netcoreapp2.1", "netcoreapp2.1")] + [InlineData("netcoreapp2.1", "netcoreapp21")] + [InlineData("netcoreapp21", "netcoreapp2.1")] + [InlineData("netcoreapp21", "netcoreapp21")] + [InlineData("netcoreapp3.1", "netcoreapp3.1")] + [InlineData("netcoreapp3.1", "netcoreapp31")] + [InlineData("netcoreapp31", "netcoreapp3.1")] + [InlineData("netcoreapp31", "netcoreapp31")] public void NuGetFramework_TryParseCommonFramework_ParsesCommonFrameworks(string frameworkString1, string frameworkString2) { var framework1 = NuGetFramework.Parse(frameworkString1); diff --git a/test/NuGet.Core.Tests/NuGet.Frameworks.Test/NuGetFrameworkTests.cs b/test/NuGet.Core.Tests/NuGet.Frameworks.Test/NuGetFrameworkTests.cs index 176ad4cadfb..30f58c31664 100644 --- a/test/NuGet.Core.Tests/NuGet.Frameworks.Test/NuGetFrameworkTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Frameworks.Test/NuGetFrameworkTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -12,6 +12,8 @@ public class NuGetFrameworkTests { [Theory] [InlineData("net45", "net45")] + [InlineData("net5.0", "net5.0")] + [InlineData("net50", "net5.0")] [InlineData("portable-net45+win8+monoandroid", "portable-net45+win8")] [InlineData("portable-net45+win8+xamarin.ios", "portable-net45+win8")] [InlineData("portable-net45+win8", "portable-net45+win8")] @@ -40,6 +42,19 @@ public void NuGetFramework_ShortName(string input, string expected) Assert.Equal(expected, result); } + [Theory] + [InlineData("net5.0", ".NETCoreApp,Version=v5.0")] + [InlineData("net452", ".NETFramework,Version=v4.5.2")] + [InlineData("netcoreapp3.1", ".NETCoreApp,Version=v3.1")] + public void NuGetFramework_GetDotNetFrameworkName(string input, string expected) + { + var fw = NuGetFramework.Parse(input); + + string result = fw.GetDotNetFrameworkName(DefaultFrameworkNameProvider.Instance); + + Assert.Equal(expected, result); + } + public static TheoryData EqualsFrameworkData { get diff --git a/test/NuGet.Core.Tests/NuGet.Protocol.Tests/PackageMetadataResourceV2FeedTests.cs b/test/NuGet.Core.Tests/NuGet.Protocol.Tests/PackageMetadataResourceV2FeedTests.cs index b3bcce74989..a6cab431890 100644 --- a/test/NuGet.Core.Tests/NuGet.Protocol.Tests/PackageMetadataResourceV2FeedTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Protocol.Tests/PackageMetadataResourceV2FeedTests.cs @@ -56,7 +56,7 @@ public async Task PackageMetadataResource_Basic() Assert.Equal("A client library for working with Microsoft Azure storage services including blobs, files, tables, and queues.", latestPackage.Summary); Assert.Equal("Microsoft Azure Storage Table Blob File Queue Scalable windowsazureofficial", latestPackage.Tags); Assert.Equal(6, latestPackage.DependencySets.Count()); - Assert.Equal("dotnet5.4", latestPackage.DependencySets.First().TargetFramework.GetShortFolderName()); + Assert.Equal("dotnet54", latestPackage.DependencySets.First().TargetFramework.GetShortFolderName()); } [Fact] diff --git a/test/NuGet.Core.Tests/NuGet.Protocol.Tests/V2FeedParserTests.cs b/test/NuGet.Core.Tests/NuGet.Protocol.Tests/V2FeedParserTests.cs index 4dba7ddb6df..545b8e31274 100644 --- a/test/NuGet.Core.Tests/NuGet.Protocol.Tests/V2FeedParserTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Protocol.Tests/V2FeedParserTests.cs @@ -116,7 +116,7 @@ public async Task V2FeedParser_FindPackagesByIdAsync() Assert.Equal("Microsoft Azure Storage Table Blob File Queue Scalable windowsazureofficial", latest.Tags); Assert.Equal("Microsoft.Data.OData:5.6.4:dotnet54|Microsoft.Data.Services.Client:5.6.4:dotnet54|System.Spatial:5.6.4:dotnet54|Newtonsoft.Json:6.0.8:dotnet54|System.Collections:4.0.11-beta-23225:dotnet54|System.Collections.Concurrent:4.0.11-beta-23225:dotnet54|System.Collections.Specialized:4.0.0-beta-23109:dotnet54|System.Diagnostics.Debug:4.0.11-beta-23225:dotnet54|System.Diagnostics.Tools:4.0.1-beta-23225:dotnet54|System.Diagnostics.TraceSource:4.0.0-beta-23225:dotnet54|System.Diagnostics.Tracing:4.0.21-beta-23225:dotnet54|System.Dynamic.Runtime:4.0.11-beta-23225:dotnet54|System.Globalization:4.0.11-beta-23225:dotnet54|System.IO:4.0.11-beta-23225:dotnet54|System.IO.FileSystem:4.0.1-beta-23225:dotnet54|System.IO.FileSystem.Primitives:4.0.1-beta-23225:dotnet54|System.Linq:4.0.1-beta-23225:dotnet54|System.Linq.Expressions:4.0.11-beta-23225:dotnet54|System.Linq.Queryable:4.0.0-beta-23109:dotnet54|System.Net.Http:4.0.1-beta-23225:dotnet54|System.Net.Primitives:4.0.11-beta-23225:dotnet54|System.Reflection:4.1.0-beta-23225:dotnet54|System.Reflection.Extensions:4.0.1-beta-23225:dotnet54|System.Reflection.TypeExtensions:4.0.1-beta-23225:dotnet54|System.Runtime:4.0.20-beta-23109:dotnet54|System.Runtime.Extensions:4.0.11-beta-23225:dotnet54|System.Runtime.InteropServices:4.0.21-beta-23225:dotnet54|System.Runtime.Serialization.Primitives:4.0.0-beta-23109:dotnet54|System.Runtime.Serialization.Xml:4.0.10-beta-23109:dotnet54|System.Security.Cryptography.Encoding:4.0.0-beta-23225:dotnet54|System.Security.Cryptography.Primitives:4.0.0-beta-23225:dotnet54|System.Security.Cryptography.Algorithms:4.0.0-beta-23225:dotnet54|System.Text.Encoding:4.0.11-beta-23225:dotnet54|System.Text.Encoding.Extensions:4.0.11-beta-23225:dotnet54|System.Text.RegularExpressions:4.0.11-beta-23225:dotnet54|System.Threading:4.0.11-beta-23225:dotnet54|System.Threading.Tasks:4.0.11-beta-23225:dotnet54|System.Threading.Thread:4.0.0-beta-23225:dotnet54|System.Threading.ThreadPool:4.0.10-beta-23225:dotnet54|System.Threading.Timer:4.0.1-beta-23225:dotnet54|System.Xml.ReaderWriter:4.0.11-beta-23225:dotnet54|System.Xml.XDocument:4.0.11-beta-23225:dotnet54|System.Xml.XmlSerializer:4.0.0-beta-23109:dotnet54|Microsoft.Data.OData:5.6.4:net40-Client|Newtonsoft.Json:6.0.8:net40-Client|Microsoft.Data.Services.Client:5.6.4:net40-Client|Microsoft.Azure.KeyVault.Core:1.0.0:net40-Client|Microsoft.Data.OData:5.6.4:win80|Newtonsoft.Json:6.0.8:win80|Microsoft.Data.OData:5.6.4:wpa|Newtonsoft.Json:6.0.8:wpa|Microsoft.Data.OData:5.6.4:wp80|Newtonsoft.Json:6.0.8:wp80|Microsoft.Azure.KeyVault.Core:1.0.0:wp80|Microsoft.Data.OData:5.6.4:portable-net45+win+wpa81+MonoAndroid10+MonoTouch10|Newtonsoft.Json:6.0.8:portable-net45+win+wpa81+MonoAndroid10+MonoTouch10", latest.Dependencies); Assert.Equal(6, latest.DependencySets.Count()); - Assert.Equal("dotnet5.4", latest.DependencySets.First().TargetFramework.GetShortFolderName()); + Assert.Equal("dotnet54", latest.DependencySets.First().TargetFramework.GetShortFolderName()); } [Fact] @@ -861,4 +861,4 @@ public async Task V2FeedParser_FollowNextLinksCached() Assert.Equal(110, packages.Count()); } } -} \ No newline at end of file +}