Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 0 additions & 6 deletions src/Tasks/Microsoft.NET.Build.Tasks/GetPackagesToPrune.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,6 @@ static Dictionary<string, NuGetVersion> LoadPackagesToPruneFromFrameworkPackages
{
var nugetFramework = new NuGetFramework(targetFrameworkIdentifier, Version.Parse(targetFrameworkVersion));

// FrameworkPackages just has data for .NET Framework 4.6.1, so turn on fallback for anything greater than that so it will resolve to the .NET Framework 4.6.1 data
if (!acceptNearestMatch && nugetFramework.IsDesktop() && nugetFramework.Version > new Version(4,6,1))
{
acceptNearestMatch = true;
}

var frameworkPackages = FrameworkPackages.GetFrameworkPackages(nugetFramework, [frameworkReference], acceptNearestMatch)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we ever want nearest match behavior at all. Is there a scenario where we actually need it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were also using the nearest match as part of a workaround for dotnet/windowsdesktop#4904. That may not be needed any more but I think we should keep this change as small as possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can delete in V.Next in conjunction with measuring that deleting it has zero change on all known TFMs. Just brute force and diff.

.SelectMany(packages => packages)
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,45 @@ public void WithMultitargetedProjects_PruningsDefaultsAreApplies(string framewor
}
}

[Fact]
public void WithMultitargetedProject_NETFrameworkIsNotPruned()
{
var project = new TestProject("MultitargetedPruning")
{
TargetFrameworks = ToolsetInfo.CurrentTargetFramework + ";net462",
};
project.PackageReferences.Add(new TestPackageReference("System.ValueTuple", "4.6.1"));
project.SourceFiles.Add("Test.cs", @"
public class Class1
{
public (int, int) GetTuple() => (1, 2);
}
");
var testAsset = _testAssetsManager.CreateTestProject(project, identifier: "NETFrameworkIsNotPruned");
var buildCommand = new BuildCommand(testAsset);
buildCommand.Execute().Should().Pass();
var assetsFilePath = Path.Combine(buildCommand.GetBaseIntermediateDirectory().FullName, "project.assets.json");
var lockFile = LockFileUtilities.GetLockFile(assetsFilePath, new NullLogger());

foreach (var lockFileTarget in lockFile.Targets)
{
var valueTupleLibrary = lockFileTarget.Libraries.Where(library => library.Name.Equals("System.ValueTuple", StringComparison.OrdinalIgnoreCase)).Single();
var runtimeAssemblies = valueTupleLibrary.RuntimeAssemblies.Where(a => !Path.GetFileName(a.Path).Equals("_._"));
var compileTimeAssemblies = valueTupleLibrary.CompileTimeAssemblies.Where(a => !Path.GetFileName(a.Path).Equals("_._"));

if (lockFileTarget.TargetFramework.Framework.Equals(".NETFramework", StringComparison.OrdinalIgnoreCase))
{
runtimeAssemblies.Should().NotBeEmpty();
compileTimeAssemblies.Should().NotBeEmpty();
}
else
{
runtimeAssemblies.Should().BeEmpty();
compileTimeAssemblies.Should().BeEmpty();
}
}
}

static List<KeyValuePair<string, string>> ParsePrunePackageReferenceJson(string json)
{
List<KeyValuePair<string, string>> ret = new();
Expand Down
Loading