Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0f6af0

Browse files
authored
Don't fall back to .NET Standard package pruning for .NET Framework (#51288)
2 parents 6f4d94a + a59f24e commit b0f6af0

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/GetPackagesToPrune.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,6 @@ static Dictionary<string, NuGetVersion> LoadPackagesToPruneFromFrameworkPackages
235235
{
236236
var nugetFramework = new NuGetFramework(targetFrameworkIdentifier, Version.Parse(targetFrameworkVersion));
237237

238-
// 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
239-
if (!acceptNearestMatch && nugetFramework.IsDesktop() && nugetFramework.Version > new Version(4,6,1))
240-
{
241-
acceptNearestMatch = true;
242-
}
243-
244238
var frameworkPackages = FrameworkPackages.GetFrameworkPackages(nugetFramework, [frameworkReference], acceptNearestMatch)
245239
.SelectMany(packages => packages)
246240
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAnAppWithoutTransitiveProjectRefs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public void It_cleans_the_project_successfully_with_static_graph_and_isolation()
8282
"1.exe",
8383
"1.pdb",
8484
"1.exe.config",
85+
"System.Diagnostics.DiagnosticSource.dll",
8586
};
8687

8788
foreach (var targetFramework in targetFrameworks)

test/Microsoft.NET.Build.Tests/GivenThatWeWantToResolveConflicts.cs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ public void PlatformPackagesCanBePruned(bool prunePackages)
329329
[InlineData("netstandard1.1", false)]
330330
[InlineData("netstandard1.0", false)]
331331
[InlineData("net451", false)]
332-
[InlineData("net462")]
333-
[InlineData("net481")]
332+
[InlineData("net462", false)]
333+
[InlineData("net481", false)]
334334
// These target frameworks shouldn't prune packages unless explicitly enabled
335335
[InlineData("net9.0", false, "")]
336336
[InlineData("netstandard2.1", false, "")]
@@ -492,6 +492,45 @@ public void WithMultitargetedProjects_PruningsDefaultsAreApplies(string framewor
492492
}
493493
}
494494

495+
[Fact]
496+
public void WithMultitargetedProject_NETFrameworkIsNotPruned()
497+
{
498+
var project = new TestProject("MultitargetedPruning")
499+
{
500+
TargetFrameworks = ToolsetInfo.CurrentTargetFramework + ";net462",
501+
};
502+
project.PackageReferences.Add(new TestPackageReference("System.ValueTuple", "4.6.1"));
503+
project.SourceFiles.Add("Test.cs", @"
504+
public class Class1
505+
{
506+
public (int, int) GetTuple() => (1, 2);
507+
}
508+
");
509+
var testAsset = _testAssetsManager.CreateTestProject(project, identifier: "NETFrameworkIsNotPruned");
510+
var buildCommand = new BuildCommand(testAsset);
511+
buildCommand.Execute().Should().Pass();
512+
var assetsFilePath = Path.Combine(buildCommand.GetBaseIntermediateDirectory().FullName, "project.assets.json");
513+
var lockFile = LockFileUtilities.GetLockFile(assetsFilePath, new NullLogger());
514+
515+
foreach (var lockFileTarget in lockFile.Targets)
516+
{
517+
var valueTupleLibrary = lockFileTarget.Libraries.Where(library => library.Name.Equals("System.ValueTuple", StringComparison.OrdinalIgnoreCase)).Single();
518+
var runtimeAssemblies = valueTupleLibrary.RuntimeAssemblies.Where(a => !Path.GetFileName(a.Path).Equals("_._"));
519+
var compileTimeAssemblies = valueTupleLibrary.CompileTimeAssemblies.Where(a => !Path.GetFileName(a.Path).Equals("_._"));
520+
521+
if (lockFileTarget.TargetFramework.Framework.Equals(".NETFramework", StringComparison.OrdinalIgnoreCase))
522+
{
523+
runtimeAssemblies.Should().NotBeEmpty();
524+
compileTimeAssemblies.Should().NotBeEmpty();
525+
}
526+
else
527+
{
528+
runtimeAssemblies.Should().BeEmpty();
529+
compileTimeAssemblies.Should().BeEmpty();
530+
}
531+
}
532+
}
533+
495534
static List<KeyValuePair<string, string>> ParsePrunePackageReferenceJson(string json)
496535
{
497536
List<KeyValuePair<string, string>> ret = new();

0 commit comments

Comments
 (0)