From 48a548d9952a5ff576cd906cde8de42d8ae525a8 Mon Sep 17 00:00:00 2001 From: Anipik Date: Thu, 10 Jun 2021 16:36:18 -0700 Subject: [PATCH 1/6] use nuget package model and remove old frameworks and rids --- ...CompatibilePackageTargetFrameworksTests.cs | 137 +++++++++++++++--- .../GetCompatiblePackageTargetFrameworks.cs | 87 +++-------- .../NupkgParser.cs | 46 +----- .../Package.cs | 31 ++-- .../PackageAsset.cs | 30 ---- 5 files changed, 162 insertions(+), 169 deletions(-) delete mode 100644 src/Microsoft.DotNet.PackageTesting/PackageAsset.cs diff --git a/src/Microsoft.DotNet.PackageTesting.Tests/GetCompatibilePackageTargetFrameworksTests.cs b/src/Microsoft.DotNet.PackageTesting.Tests/GetCompatibilePackageTargetFrameworksTests.cs index 10b0c3bbd42..1f7bb27d1c6 100644 --- a/src/Microsoft.DotNet.PackageTesting.Tests/GetCompatibilePackageTargetFrameworksTests.cs +++ b/src/Microsoft.DotNet.PackageTesting.Tests/GetCompatibilePackageTargetFrameworksTests.cs @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using NuGet.Frameworks; using System.Collections.Generic; +using NuGet.Frameworks; using Xunit; namespace Microsoft.DotNet.PackageTesting.Tests @@ -14,31 +14,128 @@ public GetCompatibilePackageTargetFrameworksTests() GetCompatiblePackageTargetFrameworks.Initialize(); } - public static IEnumerable PackageTFMData => new List + public static IEnumerable PackageTfmData => new List { // single target framework in package - new object[] { new List { FrameworkConstants.CommonFrameworks.NetStandard20}, new List { FrameworkConstants.CommonFrameworks.NetStandard20, FrameworkConstants.CommonFrameworks.NetCoreApp20, FrameworkConstants.CommonFrameworks.Net463, FrameworkConstants.CommonFrameworks.Net461, FrameworkConstants.CommonFrameworks.Net462} }, - new object[] { new List { FrameworkConstants.CommonFrameworks.NetCoreApp20}, new List { FrameworkConstants.CommonFrameworks.NetCoreApp20} }, - new object[] { new List { FrameworkConstants.CommonFrameworks.NetCoreApp21}, new List { FrameworkConstants.CommonFrameworks.NetCoreApp21} }, - new object[] { new List { FrameworkConstants.CommonFrameworks.Net461}, new List { FrameworkConstants.CommonFrameworks.Net461} }, - new object[] { new List { FrameworkConstants.CommonFrameworks.Net45}, new List { FrameworkConstants.CommonFrameworks.Net45} }, - new object[] { new List { FrameworkConstants.CommonFrameworks.NetCoreApp30}, new List { FrameworkConstants.CommonFrameworks.NetCoreApp30} }, - new object[] { new List { FrameworkConstants.CommonFrameworks.NetCoreApp31}, new List { FrameworkConstants.CommonFrameworks.NetCoreApp31} }, - new object[] { new List { FrameworkConstants.CommonFrameworks.NetStandard21}, new List { FrameworkConstants.CommonFrameworks.NetStandard21, FrameworkConstants.CommonFrameworks.NetCoreApp30 } }, - new object[] { new List { FrameworkConstants.CommonFrameworks.NetStandard12}, new List { FrameworkConstants.CommonFrameworks.NetStandard12, FrameworkConstants.CommonFrameworks.Net451 } }, - - // two target frameworks in package - new object[] { new List { FrameworkConstants.CommonFrameworks.NetStandard20, FrameworkConstants.CommonFrameworks.Net461}, new List { FrameworkConstants.CommonFrameworks.NetStandard20, FrameworkConstants.CommonFrameworks.NetCoreApp20, FrameworkConstants.CommonFrameworks.Net463, FrameworkConstants.CommonFrameworks.Net461, FrameworkConstants.CommonFrameworks.Net462} }, - new object[] { new List { FrameworkConstants.CommonFrameworks.NetStandard20, FrameworkConstants.CommonFrameworks.NetCoreApp30}, new List { FrameworkConstants.CommonFrameworks.NetStandard20, FrameworkConstants.CommonFrameworks.NetCoreApp30, FrameworkConstants.CommonFrameworks.NetCoreApp20, FrameworkConstants.CommonFrameworks.Net463, FrameworkConstants.CommonFrameworks.Net461, FrameworkConstants.CommonFrameworks.Net462} }, - new object[] { new List { FrameworkConstants.CommonFrameworks.NetCoreApp30, FrameworkConstants.CommonFrameworks.Net461}, new List { FrameworkConstants.CommonFrameworks.NetCoreApp30, FrameworkConstants.CommonFrameworks.Net461} }, - new object[] { new List { FrameworkConstants.CommonFrameworks.NetCoreApp30, FrameworkConstants.CommonFrameworks.Net50}, new List { FrameworkConstants.CommonFrameworks.NetCoreApp30, FrameworkConstants.CommonFrameworks.Net50} }, + new object[] + { + new List + { + @"lib/netstandard2.0/TestPackage.dll", + }, + new List + { + FrameworkConstants.CommonFrameworks.NetStandard20, + FrameworkConstants.CommonFrameworks.Net461, + FrameworkConstants.CommonFrameworks.Net462, + FrameworkConstants.CommonFrameworks.NetCoreApp31 + } + }, + new object[] + { + new List + { + @"runtimes/win/lib/netstandard2.0/TestPackage.dll", + }, + new List + { + FrameworkConstants.CommonFrameworks.NetStandard20, + FrameworkConstants.CommonFrameworks.Net461, + FrameworkConstants.CommonFrameworks.Net462, + FrameworkConstants.CommonFrameworks.NetCoreApp31 + } + }, + new object[] + { + new List + { + @"lib/net5.0/TestPackage.dll", + @"runtimes/win/lib/netstandard2.0/TestPackage.dll" + }, + new List + { + FrameworkConstants.CommonFrameworks.NetStandard20, + FrameworkConstants.CommonFrameworks.Net461, + FrameworkConstants.CommonFrameworks.Net462, + FrameworkConstants.CommonFrameworks.NetCoreApp31, + FrameworkConstants.CommonFrameworks.Net50 + } + }, + new object[] + { + new List + { + @"lib/netcoreapp3.1/TestPackage.dll" + }, + new List + { + FrameworkConstants.CommonFrameworks.NetCoreApp31 + } + }, + new object[] + { + new List + { + @"lib/netcoreapp3.1/TestPackage.dll", + @"lib/net461/TestPackage.dll" + }, + new List + { + FrameworkConstants.CommonFrameworks.NetCoreApp31, + FrameworkConstants.CommonFrameworks.Net461 + } + }, + new object[] + { + new List + { + @"runtimes/unix/lib/netcoreapp3.1/TestPackage.dll", + @"runtimes/win/lib/netstandard2.0/TestPackage.dll" + }, + new List + { + FrameworkConstants.CommonFrameworks.NetCoreApp31, + FrameworkConstants.CommonFrameworks.NetStandard20, + FrameworkConstants.CommonFrameworks.Net461, + FrameworkConstants.CommonFrameworks.Net462 + } + }, + new object[] + { + new List + { + @"lib/net5.0/TestPackage.dll", + @"lib/net472/TestPackage.dll", + @"runtimes/win/lib/netstandard2.0/TestPackage.dll" + }, + new List + { + FrameworkConstants.CommonFrameworks.NetStandard20, + FrameworkConstants.CommonFrameworks.Net461, + FrameworkConstants.CommonFrameworks.Net462, + FrameworkConstants.CommonFrameworks.NetCoreApp31, + FrameworkConstants.CommonFrameworks.Net50 + } + }, + new object[] + { + new List + { + @"lib/net461/TestPackage.dll" + }, + new List + { + FrameworkConstants.CommonFrameworks.Net461, + } + }, }; [Theory] - [MemberData(nameof(PackageTFMData))] - public void GetCompatibleFrameworks(List packageFrameworks, List expectedTestFrameworks) + [MemberData(nameof(PackageTfmData))] + public void GetCompatibleFrameworks(List filePaths, List expectedTestFrameworks) { - List actualTestFrameworks = GetCompatiblePackageTargetFrameworks.GetTestFrameworks(packageFrameworks); + Package package = new("TestPackage", "1.0.0", filePaths); + List actualTestFrameworks = GetCompatiblePackageTargetFrameworks.GetTestFrameworks(package, "netcoreapp3.1"); CollectionsEqual(expectedTestFrameworks, actualTestFrameworks); } diff --git a/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs b/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs index 2fee0d7edfc..34ba0987c30 100644 --- a/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs +++ b/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs @@ -19,6 +19,8 @@ public class GetCompatiblePackageTargetFrameworks : BuildTask [Required] public string[] PackagePaths { get; set; } + public string MinDotnetTargetFramework { get; set; } + [Output] public ITaskItem[] TestProjects { get; set; } @@ -32,12 +34,11 @@ public override bool Execute() foreach (var packagePath in PackagePaths) { Package package = NupkgParser.CreatePackageObject(packagePath); - List packageTargetFrameworks = package.PackageAssets.Select(asset => asset.TargetFramework).Where(tfm => tfm != null).Distinct().ToList(); - List frameworksToTest = GetTestFrameworks(packageTargetFrameworks); - testProjects.AddRange(CreateItemFromTestFramework(package.PackageId, package.Version, frameworksToTest, GetRidsFromPackage(package))); + List testFrameworks = GetTestFrameworks(package, MinDotnetTargetFramework); + testProjects.AddRange(CreateItemFromTestFramework(package.PackageId, package.Version, testFrameworks)); } - + // Removing empty items. TestProjects = testProjects.Where(tfm => tfm.ItemSpec != "").ToArray(); } @@ -45,56 +46,42 @@ public override bool Execute() { Log.LogErrorFromException(e, showStackTrace: false); } - + return result && !Log.HasLoggedErrors; } - public static List GetTestFrameworks(List packageTargetFrameworks) + public static List GetTestFrameworks(Package package, string minDotnetTargetFramework) { - List frameworksToTest = new List(); + List frameworksToTest= new List(); + IEnumerable packageTargetFrameworks = package.FrameworksInPackage; // Testing the package installation on all tfms linked with package targetframeworks. foreach (var item in packageTargetFrameworks) { if (packageTfmMapping.ContainsKey(item)) - frameworksToTest.AddRange(packageTfmMapping[item].ToList()); + { + frameworksToTest.AddRange(packageTfmMapping[item]); + } + // Adding the frameworks in the packages to the test matrix. + frameworksToTest.Add(item); } - // Pruning the test matrix by removing the frameworks we dont want to test. - frameworksToTest = frameworksToTest.Where(tfm => allTargetFrameworks.Contains(tfm)).ToList(); + if (!string.IsNullOrEmpty(minDotnetTargetFramework) && frameworksToTest.Contains(FrameworkConstants.CommonFrameworks.NetStandard20)) + frameworksToTest.Add(NuGetFramework.Parse(minDotnetTargetFramework)); - // Adding the frameworks in the packages to the test matrix; - frameworksToTest.AddRange(packageTargetFrameworks); - frameworksToTest = frameworksToTest.Distinct().ToList(); + frameworksToTest = frameworksToTest.Where(tfm => allTargetFrameworks.Contains(tfm)).Distinct().ToList(); return frameworksToTest; } public static void Initialize() { // Defining the set of known frameworks that we care to test - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetCoreApp20); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetCoreApp21); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetCoreApp30); allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetCoreApp31); allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.Net50); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.Net45); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.Net451); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.Net452); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.Net46); allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.Net461); allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.Net462); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.Net463); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetStandard10); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetStandard11); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetStandard12); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetStandard13); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetStandard14); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetStandard15); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetStandard16); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetStandard17); allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetStandard20); allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetStandard21); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.UAP10); // creating a map framework in package => frameworks to test based on default compatibilty mapping. foreach (var item in DefaultFrameworkMappings.Instance.CompatibilityMappings) @@ -111,52 +98,20 @@ public static void Initialize() } } } - - public List CreateItemFromTestFramework(string packageId, string version, List testFrameworks, string rids) + + public List CreateItemFromTestFramework(string packageId, string version, List targetFrameworks) { List testprojects = new List(); - foreach (var framework in testFrameworks) + foreach (var framework in targetFrameworks) { var supportedPackage = new TaskItem(packageId); supportedPackage.SetMetadata("Version", version); supportedPackage.SetMetadata("TargetFramework", framework.ToString()); supportedPackage.SetMetadata("TargetFrameworkShort", framework.GetShortFolderName()); - - if (!String.IsNullOrEmpty(rids)) - { - supportedPackage.SetMetadata("RuntimeIdentifiers", rids); - } testprojects.Add(supportedPackage); } return testprojects; } - - public string GetRidsFromPackage(Package package) - { - List rids = new List(); - foreach (var item in package.PackageAssets) - { - if (item.AssetType == AssetType.RuntimeAsset) - { - string testRid = item.Rid; - string testArch = testRid == "browser" ? "-wasm" : "-x64"; - if (testRid == "unix") - { - if (!rids.Contains("linux" + testArch)) - rids.Add("linux" + testArch); - - if (!rids.Contains("osx" + testArch)) - rids.Add("osx" + testArch); - } - else - { - if (!rids.Contains(testRid + testArch)) - rids.Add(testRid + testArch); - } - } - } - return string.Join(";", rids); - } - } + } } diff --git a/src/Microsoft.DotNet.PackageTesting/NupkgParser.cs b/src/Microsoft.DotNet.PackageTesting/NupkgParser.cs index bb1881c1657..9832e3f592a 100644 --- a/src/Microsoft.DotNet.PackageTesting/NupkgParser.cs +++ b/src/Microsoft.DotNet.PackageTesting/NupkgParser.cs @@ -1,11 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using NuGet.Frameworks; -using NuGet.Packaging; -using NuGet.Packaging.Core; -using System.Collections.Generic; using System.Linq; +using NuGet.Packaging; namespace Microsoft.DotNet.PackageTesting { @@ -13,52 +10,13 @@ public class NupkgParser { public static Package CreatePackageObject(string packagePath) { - List packageAssets = new List(); - Dictionary> packageDependencies = new Dictionary>(); - PackageArchiveReader nupkgReader = new PackageArchiveReader(packagePath); NuspecReader nuspecReader = nupkgReader.NuspecReader; string packageId = nuspecReader.GetId(); string version = nuspecReader.GetVersion().ToString(); - IEnumerable dependencyGroups = nuspecReader.GetDependencyGroups(); - - foreach (var item in dependencyGroups) - { - packageDependencies.Add(item.TargetFramework, item.Packages.ToList()); - } - - var files = nupkgReader.GetFiles().ToList().Where(t => t.EndsWith(".dll")).Where(t => t.Contains(packageId + ".dll")); - foreach (var file in files) - { - packageAssets.Add(ExtractAssetFromFile(file)); - } - - return new Package(packageId, version, packageAssets, packageDependencies); - } - - public static PackageAsset ExtractAssetFromFile(string filePath) - { - PackageAsset asset = null; - if (filePath.StartsWith("ref")) - { - var stringParts = filePath.Split('/'); - asset = new PackageAsset(NuGetFramework.Parse(stringParts[1]), null, filePath, AssetType.RefAsset); - } - else if (filePath.StartsWith("lib")) - { - var stringParts = filePath.Split('/'); - asset = new PackageAsset(NuGetFramework.Parse(stringParts[1]), null, filePath, AssetType.LibAsset); - - } - else if (filePath.StartsWith("runtimes")) - { - var stringParts = filePath.Split('/'); - NuGetFramework framework = stringParts.Length > 3 ? NuGetFramework.Parse(stringParts[3]) : null; - asset = new PackageAsset(framework, stringParts[1], filePath, AssetType.RuntimeAsset); - } - return asset; + return new Package(packageId, version, nupkgReader.GetFiles()?.Where(t => t.EndsWith(packageId + ".dll"))); } } } diff --git a/src/Microsoft.DotNet.PackageTesting/Package.cs b/src/Microsoft.DotNet.PackageTesting/Package.cs index 1e4b7b291e9..b0e2f097dc6 100644 --- a/src/Microsoft.DotNet.PackageTesting/Package.cs +++ b/src/Microsoft.DotNet.PackageTesting/Package.cs @@ -1,24 +1,37 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using NuGet.Frameworks; -using NuGet.Packaging.Core; using System.Collections.Generic; +using System.Linq; +using NuGet.Client; +using NuGet.ContentModel; +using NuGet.Frameworks; namespace Microsoft.DotNet.PackageTesting { public class Package { - public List PackageAssets { get; set; } - public string PackageId { get; set; } - public string Version { get; set; } - public Dictionary> PackageDependencies { get; set; } - public Package(string packageId, string version, List packageAssets, Dictionary> packageDependencies) + public Package(string packageId, string version, IEnumerable packageAssetPaths) { PackageId = packageId; Version = version; - PackageAssets = packageAssets; - PackageDependencies = packageDependencies; + + ContentItemCollection packageAssets = new(); + packageAssets.Load(packageAssetPaths); + ManagedCodeConventions conventions = new ManagedCodeConventions(null); + + IEnumerable RefAssets = packageAssets.FindItems(conventions.Patterns.CompileRefAssemblies); + IEnumerable LibAssets = packageAssets.FindItems(conventions.Patterns.CompileLibAssemblies); + IEnumerable CompileAssets = RefAssets.Any() ? RefAssets : LibAssets; + List FrameworksInPackageList = CompileAssets?.Select(t => (NuGetFramework)t.Properties["tfm"]).ToList(); + + IEnumerable RuntimeAssets = packageAssets.FindItems(conventions.Patterns.RuntimeAssemblies); + FrameworksInPackageList.AddRange(RuntimeAssets?.Select(t => (NuGetFramework)t.Properties["tfm"]).Distinct()); + FrameworksInPackage = FrameworksInPackageList.Distinct(); } + + public string PackageId { get; set; } + public string Version { get; set; } + public IEnumerable FrameworksInPackage { get; private set; } } } diff --git a/src/Microsoft.DotNet.PackageTesting/PackageAsset.cs b/src/Microsoft.DotNet.PackageTesting/PackageAsset.cs deleted file mode 100644 index 825a4dad481..00000000000 --- a/src/Microsoft.DotNet.PackageTesting/PackageAsset.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using NuGet.Frameworks; - -namespace Microsoft.DotNet.PackageTesting -{ - public class PackageAsset - { - public NuGetFramework TargetFramework { get; set; } - public string Rid { get; set; } - public string PackagePath { get; set; } - public AssetType AssetType { get; set; } - - public PackageAsset(NuGetFramework targetFramework, string runtimeIdentifier, string packagePath, AssetType assetType) - { - TargetFramework = targetFramework; - Rid = runtimeIdentifier; - PackagePath = packagePath; - AssetType = assetType; - } - } - - public enum AssetType - { - RefAsset = 0, - LibAsset = 1, - RuntimeAsset = 2 - } -} From 7e678e97a653652564276911c97a286b3eb29465 Mon Sep 17 00:00:00 2001 From: Anipik Date: Thu, 10 Jun 2021 16:45:24 -0700 Subject: [PATCH 2/6] some more formatting --- .../GetCompatibilePackageTargetFrameworksTests.cs | 4 ++-- .../GetCompatiblePackageTargetFrameworks.cs | 13 +++++-------- src/Microsoft.DotNet.PackageTesting/Package.cs | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.DotNet.PackageTesting.Tests/GetCompatibilePackageTargetFrameworksTests.cs b/src/Microsoft.DotNet.PackageTesting.Tests/GetCompatibilePackageTargetFrameworksTests.cs index 1f7bb27d1c6..5d61f29ec66 100644 --- a/src/Microsoft.DotNet.PackageTesting.Tests/GetCompatibilePackageTargetFrameworksTests.cs +++ b/src/Microsoft.DotNet.PackageTesting.Tests/GetCompatibilePackageTargetFrameworksTests.cs @@ -21,7 +21,7 @@ public GetCompatibilePackageTargetFrameworksTests() { new List { - @"lib/netstandard2.0/TestPackage.dll", + @"lib/netstandard2.0/TestPackage.dll" }, new List { @@ -135,7 +135,7 @@ public GetCompatibilePackageTargetFrameworksTests() public void GetCompatibleFrameworks(List filePaths, List expectedTestFrameworks) { Package package = new("TestPackage", "1.0.0", filePaths); - List actualTestFrameworks = GetCompatiblePackageTargetFrameworks.GetTestFrameworks(package, "netcoreapp3.1"); + IEnumerable actualTestFrameworks = GetCompatiblePackageTargetFrameworks.GetTestFrameworks(package, "netcoreapp3.1"); CollectionsEqual(expectedTestFrameworks, actualTestFrameworks); } diff --git a/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs b/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs index 34ba0987c30..3cb4e097379 100644 --- a/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs +++ b/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs @@ -35,7 +35,7 @@ public override bool Execute() { Package package = NupkgParser.CreatePackageObject(packagePath); - List testFrameworks = GetTestFrameworks(package, MinDotnetTargetFramework); + IEnumerable testFrameworks = GetTestFrameworks(package, MinDotnetTargetFramework); testProjects.AddRange(CreateItemFromTestFramework(package.PackageId, package.Version, testFrameworks)); } @@ -50,7 +50,7 @@ public override bool Execute() return result && !Log.HasLoggedErrors; } - public static List GetTestFrameworks(Package package, string minDotnetTargetFramework) + public static IEnumerable GetTestFrameworks(Package package, string minDotnetTargetFramework) { List frameworksToTest= new List(); IEnumerable packageTargetFrameworks = package.FrameworksInPackage; @@ -59,9 +59,7 @@ public static List GetTestFrameworks(Package package, string min foreach (var item in packageTargetFrameworks) { if (packageTfmMapping.ContainsKey(item)) - { frameworksToTest.AddRange(packageTfmMapping[item]); - } // Adding the frameworks in the packages to the test matrix. frameworksToTest.Add(item); } @@ -69,8 +67,7 @@ public static List GetTestFrameworks(Package package, string min if (!string.IsNullOrEmpty(minDotnetTargetFramework) && frameworksToTest.Contains(FrameworkConstants.CommonFrameworks.NetStandard20)) frameworksToTest.Add(NuGetFramework.Parse(minDotnetTargetFramework)); - frameworksToTest = frameworksToTest.Where(tfm => allTargetFrameworks.Contains(tfm)).Distinct().ToList(); - return frameworksToTest; + return frameworksToTest.Where(tfm => allTargetFrameworks.Contains(tfm)).Distinct(); } public static void Initialize() @@ -99,10 +96,10 @@ public static void Initialize() } } - public List CreateItemFromTestFramework(string packageId, string version, List targetFrameworks) + public List CreateItemFromTestFramework(string packageId, string version, IEnumerable testFrameworks) { List testprojects = new List(); - foreach (var framework in targetFrameworks) + foreach (var framework in testFrameworks) { var supportedPackage = new TaskItem(packageId); supportedPackage.SetMetadata("Version", version); diff --git a/src/Microsoft.DotNet.PackageTesting/Package.cs b/src/Microsoft.DotNet.PackageTesting/Package.cs index b0e2f097dc6..8574dea2e3a 100644 --- a/src/Microsoft.DotNet.PackageTesting/Package.cs +++ b/src/Microsoft.DotNet.PackageTesting/Package.cs @@ -23,10 +23,10 @@ public Package(string packageId, string version, IEnumerable packageAsse IEnumerable RefAssets = packageAssets.FindItems(conventions.Patterns.CompileRefAssemblies); IEnumerable LibAssets = packageAssets.FindItems(conventions.Patterns.CompileLibAssemblies); IEnumerable CompileAssets = RefAssets.Any() ? RefAssets : LibAssets; - List FrameworksInPackageList = CompileAssets?.Select(t => (NuGetFramework)t.Properties["tfm"]).ToList(); + List FrameworksInPackageList = CompileAssets.Select(t => (NuGetFramework)t.Properties["tfm"]).ToList(); IEnumerable RuntimeAssets = packageAssets.FindItems(conventions.Patterns.RuntimeAssemblies); - FrameworksInPackageList.AddRange(RuntimeAssets?.Select(t => (NuGetFramework)t.Properties["tfm"]).Distinct()); + FrameworksInPackageList.AddRange(RuntimeAssets.Select(t => (NuGetFramework)t.Properties["tfm"]).Distinct()); FrameworksInPackage = FrameworksInPackageList.Distinct(); } From 7334b2a0de13a07070b83dbe6a637cc15cde988c Mon Sep 17 00:00:00 2001 From: Anipik Date: Fri, 11 Jun 2021 10:26:12 -0700 Subject: [PATCH 3/6] fix netcoreapp tests --- .../Microsoft.DotNet.PackageTesting.Tests.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.DotNet.PackageTesting.Tests/Microsoft.DotNet.PackageTesting.Tests.csproj b/src/Microsoft.DotNet.PackageTesting.Tests/Microsoft.DotNet.PackageTesting.Tests.csproj index 21973221994..fb54391f150 100644 --- a/src/Microsoft.DotNet.PackageTesting.Tests/Microsoft.DotNet.PackageTesting.Tests.csproj +++ b/src/Microsoft.DotNet.PackageTesting.Tests/Microsoft.DotNet.PackageTesting.Tests.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1;net472 @@ -8,6 +8,7 @@ + From c1f390388e9bd5667b55db750187083e974201e6 Mon Sep 17 00:00:00 2001 From: Anipik Date: Fri, 11 Jun 2021 11:24:49 -0700 Subject: [PATCH 4/6] automatic calculate the min supported dotnet version, add input for all supported frameworks and add min dotnet version for packages contatining netstandard config --- ...CompatibilePackageTargetFrameworksTests.cs | 3 ++- .../GetCompatiblePackageTargetFrameworks.cs | 23 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.DotNet.PackageTesting.Tests/GetCompatibilePackageTargetFrameworksTests.cs b/src/Microsoft.DotNet.PackageTesting.Tests/GetCompatibilePackageTargetFrameworksTests.cs index 5d61f29ec66..949b15ceccc 100644 --- a/src/Microsoft.DotNet.PackageTesting.Tests/GetCompatibilePackageTargetFrameworksTests.cs +++ b/src/Microsoft.DotNet.PackageTesting.Tests/GetCompatibilePackageTargetFrameworksTests.cs @@ -11,7 +11,7 @@ public class GetCompatibilePackageTargetFrameworksTests { public GetCompatibilePackageTargetFrameworksTests() { - GetCompatiblePackageTargetFrameworks.Initialize(); + GetCompatiblePackageTargetFrameworks.Initialize("netcoreapp3.1;net5.0;net6.0;net461;net462;net471;net472;netstandard2.0;netstandard2.1"); } public static IEnumerable PackageTfmData => new List @@ -113,6 +113,7 @@ public GetCompatibilePackageTargetFrameworksTests() FrameworkConstants.CommonFrameworks.NetStandard20, FrameworkConstants.CommonFrameworks.Net461, FrameworkConstants.CommonFrameworks.Net462, + NuGetFramework.Parse("net472"), FrameworkConstants.CommonFrameworks.NetCoreApp31, FrameworkConstants.CommonFrameworks.Net50 } diff --git a/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs b/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs index 3cb4e097379..2b2ed1ad386 100644 --- a/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs +++ b/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs @@ -19,7 +19,8 @@ public class GetCompatiblePackageTargetFrameworks : BuildTask [Required] public string[] PackagePaths { get; set; } - public string MinDotnetTargetFramework { get; set; } + [Required] + public string SupportedFrameworks { get; set; } [Output] public ITaskItem[] TestProjects { get; set; } @@ -30,12 +31,14 @@ public override bool Execute() List testProjects = new List(); try { - Initialize(); + Initialize(SupportedFrameworks); + string minDotnetTargetFramework = allTargetFrameworks.Where(t => t.Framework == ".NETCoreApp").OrderBy(t => t.Version).FirstOrDefault()?.GetShortFolderName(); + foreach (var packagePath in PackagePaths) { Package package = NupkgParser.CreatePackageObject(packagePath); - IEnumerable testFrameworks = GetTestFrameworks(package, MinDotnetTargetFramework); + IEnumerable testFrameworks = GetTestFrameworks(package, minDotnetTargetFramework); testProjects.AddRange(CreateItemFromTestFramework(package.PackageId, package.Version, testFrameworks)); } @@ -64,21 +67,19 @@ public static IEnumerable GetTestFrameworks(Package package, str frameworksToTest.Add(item); } - if (!string.IsNullOrEmpty(minDotnetTargetFramework) && frameworksToTest.Contains(FrameworkConstants.CommonFrameworks.NetStandard20)) + if (!string.IsNullOrEmpty(minDotnetTargetFramework) && frameworksToTest.Any(t => t.Framework == ".NETStandard")) frameworksToTest.Add(NuGetFramework.Parse(minDotnetTargetFramework)); return frameworksToTest.Where(tfm => allTargetFrameworks.Contains(tfm)).Distinct(); } - public static void Initialize() + public static void Initialize(string targetFrameworks) { // Defining the set of known frameworks that we care to test - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetCoreApp31); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.Net50); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.Net461); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.Net462); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetStandard20); - allTargetFrameworks.Add(FrameworkConstants.CommonFrameworks.NetStandard21); + foreach (var tfm in targetFrameworks.Split(';')) + { + allTargetFrameworks.Add(NuGetFramework.Parse(tfm)); + } // creating a map framework in package => frameworks to test based on default compatibilty mapping. foreach (var item in DefaultFrameworkMappings.Instance.CompatibilityMappings) From 9fefdaff382a28c27564a3dd05d188de07e1068d Mon Sep 17 00:00:00 2001 From: Anipik Date: Mon, 14 Jun 2021 09:58:39 -0700 Subject: [PATCH 5/6] add default supported test frameworks item --- .../GetCompatiblePackageTargetFrameworks.cs | 4 ++-- .../build/Microsoft.DotNet.PackageTesting.props | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs b/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs index 2b2ed1ad386..ff00124037e 100644 --- a/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs +++ b/src/Microsoft.DotNet.PackageTesting/GetCompatiblePackageTargetFrameworks.cs @@ -20,7 +20,7 @@ public class GetCompatiblePackageTargetFrameworks : BuildTask public string[] PackagePaths { get; set; } [Required] - public string SupportedFrameworks { get; set; } + public string SupportedTestFrameworks { get; set; } [Output] public ITaskItem[] TestProjects { get; set; } @@ -31,7 +31,7 @@ public override bool Execute() List testProjects = new List(); try { - Initialize(SupportedFrameworks); + Initialize(SupportedTestFrameworks); string minDotnetTargetFramework = allTargetFrameworks.Where(t => t.Framework == ".NETCoreApp").OrderBy(t => t.Version).FirstOrDefault()?.GetShortFolderName(); foreach (var packagePath in PackagePaths) diff --git a/src/Microsoft.DotNet.PackageTesting/build/Microsoft.DotNet.PackageTesting.props b/src/Microsoft.DotNet.PackageTesting/build/Microsoft.DotNet.PackageTesting.props index 052e1689aa2..f5a70c494dd 100644 --- a/src/Microsoft.DotNet.PackageTesting/build/Microsoft.DotNet.PackageTesting.props +++ b/src/Microsoft.DotNet.PackageTesting/build/Microsoft.DotNet.PackageTesting.props @@ -3,4 +3,8 @@ $(MSBuildThisFileDirectory)..\tools\net472\Microsoft.DotNet.PackageTesting.dll $(MSBuildThisFileDirectory)..\tools\netcoreapp3.1\Microsoft.DotNet.PackageTesting.dll + + + + From 5d0e89310a987565c03351705bed23ffa2842a0e Mon Sep 17 00:00:00 2001 From: Anipik Date: Mon, 14 Jun 2021 10:24:06 -0700 Subject: [PATCH 6/6] breaking and grouping SupportedTestFramework --- .../build/Microsoft.DotNet.PackageTesting.props | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.DotNet.PackageTesting/build/Microsoft.DotNet.PackageTesting.props b/src/Microsoft.DotNet.PackageTesting/build/Microsoft.DotNet.PackageTesting.props index f5a70c494dd..5ecea08caeb 100644 --- a/src/Microsoft.DotNet.PackageTesting/build/Microsoft.DotNet.PackageTesting.props +++ b/src/Microsoft.DotNet.PackageTesting/build/Microsoft.DotNet.PackageTesting.props @@ -5,6 +5,21 @@ - + + + + + + + + + + + + + + + +