Skip to content

Include Dependency Frameworks in set of TFMs considered for package testing #7645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Linq;
using NuGet.Frameworks;
using Xunit;

Expand Down Expand Up @@ -135,11 +136,37 @@ public GetCompatibilePackageTargetFrameworksTests()
[MemberData(nameof(PackageTfmData))]
public void GetCompatibleFrameworks(List<string> filePaths, List<NuGetFramework> expectedTestFrameworks)
{
Package package = new("TestPackage", "1.0.0", filePaths);
Package package = new("TestPackage", "1.0.0", filePaths, Enumerable.Empty<NuGetFramework>());
IEnumerable<NuGetFramework> actualTestFrameworks = GetCompatiblePackageTargetFrameworks.GetTestFrameworks(package, "netcoreapp3.1");
CollectionsEqual(expectedTestFrameworks, actualTestFrameworks);
}

[Fact]
public void GetCompatibleFrameworksFromDependencies()
{
var dependencyFrameworks = new[]
{
FrameworkConstants.CommonFrameworks.NetCoreApp21,
FrameworkConstants.CommonFrameworks.NetCoreApp31,
FrameworkConstants.CommonFrameworks.NetStandard20,
FrameworkConstants.CommonFrameworks.NetStandard21,
NuGetFramework.Parse("net6.0"),
};
Package package = new("TestPackage", "1.0.0", Enumerable.Empty<string>(), dependencyFrameworks);
IEnumerable<NuGetFramework> actualTestFrameworks = GetCompatiblePackageTargetFrameworks.GetTestFrameworks(package, "netcoreapp3.1");

var expectedTestFrameworks = new[]
{
NuGetFramework.Parse("net6.0"),
FrameworkConstants.CommonFrameworks.NetCoreApp31,
FrameworkConstants.CommonFrameworks.Net461,
FrameworkConstants.CommonFrameworks.Net462,
FrameworkConstants.CommonFrameworks.NetStandard20,
FrameworkConstants.CommonFrameworks.NetStandard21
};
CollectionsEqual(expectedTestFrameworks, actualTestFrameworks);
}

private static void CollectionsEqual<T>(IEnumerable<T> T1, IEnumerable<T> T2)
{
foreach (var item in T1)
Expand Down
5 changes: 4 additions & 1 deletion src/Microsoft.DotNet.PackageTesting/NupkgParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Linq;
using NuGet.Frameworks;
using NuGet.Packaging;

namespace Microsoft.DotNet.PackageTesting
Expand All @@ -16,7 +17,9 @@ public static Package CreatePackageObject(string packagePath)
string packageId = nuspecReader.GetId();
string version = nuspecReader.GetVersion().ToString();

return new Package(packageId, version, nupkgReader.GetFiles()?.Where(t => t.EndsWith(packageId + ".dll")));
NuGetFramework[] dependencyFrameworks = nuspecReader.GetDependencyGroups().Select(dg => dg.TargetFramework).Where(tfm => tfm != null).ToArray();

return new Package(packageId, version, nupkgReader.GetFiles()?.Where(t => t.EndsWith(packageId + ".dll")), dependencyFrameworks);
}
}
}
3 changes: 2 additions & 1 deletion src/Microsoft.DotNet.PackageTesting/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.DotNet.PackageTesting
{
public class Package
{
public Package(string packageId, string version, IEnumerable<string> packageAssetPaths)
public Package(string packageId, string version, IEnumerable<string> packageAssetPaths, IEnumerable<NuGetFramework> dependencyFrameworks)
{
PackageId = packageId;
Version = version;
Expand All @@ -27,6 +27,7 @@ public Package(string packageId, string version, IEnumerable<string> packageAsse

IEnumerable<ContentItem> RuntimeAssets = packageAssets.FindItems(conventions.Patterns.RuntimeAssemblies);
FrameworksInPackageList.AddRange(RuntimeAssets.Select(t => (NuGetFramework)t.Properties["tfm"]).Distinct());
FrameworksInPackageList.AddRange(dependencyFrameworks);
FrameworksInPackage = FrameworksInPackageList.Distinct();
}

Expand Down