Skip to content

Conversation

@nkolev92
Copy link
Contributor

@nkolev92 nkolev92 commented Aug 18, 2025

Customer Impact

This PR is the SDK side of changing the package pruning defaults to be enabled for .NET 10 projects only, including ones that multi-target .NET 10.
Design details at https://github.com/NuGet/Home/blob/dev/accepted/2025/prune-package-reference-rollout-take-2.md.

Without this change multi-targeted projects will not get data.

SDK side of NuGet/NuGet.Client#6696.
Due to the fact that we want pruning (inner build feature) to be enabled for the full project when one of the TFMs is .NET 10, in multitargeted projects we should always generate the pruning data and let NuGet decide whether to use it.

Regression

No, NET 10 is the first time we're enabling the feature by default and this behavior is more restrictive than the P1-P7 behaviors.

Testing

Automation added in this PR.
The equivalent functionality is already tested on NuGet side as well.

Risk

Low, it enables pruning for more scenarios such as .NET 10 multi-targeting, but the P7 default itself is more permissive (it enables for net8.0 and above).

@nkolev92 nkolev92 changed the title Generate prunign data correctly Generate pruning data correctly Aug 18, 2025
@nkolev92
Copy link
Contributor Author

cc @dsplaisted

@nkolev92 nkolev92 marked this pull request as ready for review August 19, 2025 00:00
Copilot AI review requested due to automatic review settings August 19, 2025 00:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR modifies how pruning data is generated for multi-targeted projects to ensure compatibility with .NET 10 requirements. The change allows pruning data generation when RestoreEnablePackagePruning is empty (indicating a multi-targeted project) in addition to when it's explicitly set to true.

  • Modified the target condition to generate pruning data for multi-targeted projects even when RestoreEnablePackagePruning is not explicitly set
  • Updated test cases to verify the new behavior with additional test scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets Updated condition logic to generate pruning data for multi-targeted projects
test/Microsoft.NET.Build.Tests/GivenThatWeWantToResolveConflicts.cs Added test parameters to verify pruning behavior with different configurations

Copy link
Member

@dsplaisted dsplaisted left a comment

Choose a reason for hiding this comment

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

Should we have tests that cover the different defaults for whether pruning is on or off?

For example:

  • net9.0 - off
  • net10.0 - on
  • net9.0;net10.0 - on
  • net8.0;net9.0 - on

@nkolev92
Copy link
Contributor Author

That's a good idea.
I have those tests on the NuGet side, but they're not exercising the conditions in the SDK targets.

@dsplaisted
Copy link
Member

@nkolev92 Were you targeting .NET 10 RC1 for this? If so, it will need to be ported to the RC1 release branch, and you probably need Tactics approval.

@nkolev92
Copy link
Contributor Author

Yes, it needs ported to RC1.

@nkolev92 nkolev92 enabled auto-merge (squash) August 19, 2025 20:41
@nkolev92 nkolev92 changed the base branch from main to release/10.0.1xx-rc1 August 19, 2025 20:44
@nkolev92 nkolev92 requested review from a team as code owners August 19, 2025 20:44
@nkolev92 nkolev92 force-pushed the dev-nkolev92-generatePruningDataCorrect branch from bec8595 to 97d1fb3 Compare August 19, 2025 20:45
@nkolev92 nkolev92 force-pushed the dev-nkolev92-generatePruningDataCorrect branch from 97d1fb3 to 849eae3 Compare August 19, 2025 20:49
@nkolev92 nkolev92 changed the base branch from release/10.0.1xx-rc1 to main August 19, 2025 20:49
@nkolev92 nkolev92 changed the base branch from main to release/10.0.1xx-rc1 August 19, 2025 20:49
@nkolev92 nkolev92 merged commit 9f5c51c into release/10.0.1xx-rc1 Aug 19, 2025
27 of 28 checks passed
@nkolev92 nkolev92 deleted the dev-nkolev92-generatePruningDataCorrect branch August 19, 2025 22:27
@dsplaisted
Copy link
Member

/backport to release/10.0.1xx

@github-actions
Copy link
Contributor

Started backporting to release/10.0.1xx: https://github.com/dotnet/sdk/actions/runs/17083993349

@github-actions
Copy link
Contributor

@dsplaisted an error occurred while backporting to "release/10.0.1xx", please check the run log for details!

The process '/usr/bin/git' failed with exit code 1

@bording
Copy link

bording commented Sep 10, 2025

I see conversations here saying this needed to be ported to RC1, but as far as I can tell, this change did not actually make it into the 10.0.100-rc.1.25451.107 SDK that released yesterday.

With this change not making it in, it seems pruning is broken for multi-targeted projects. When I manually add this change to my copy of Microsoft.NET.Sdk.FrameworkReferenceResolution.targets, pruning works properly.

@dsplaisted
Copy link
Member

I think this did make it into RC1 but then it was disabled or backed out due to a perf regression. @nkolev92 can probably confirm.

@nkolev92
Copy link
Contributor Author

It was ported yeah: #50377.

Perf regression is correct, but it was only disabled in dotnet/dotnet repo: dotnet/dotnet@2a94fd4.

That change hasn't flown into the RC1 branch in this repo. Not sure if it will. I'm not 100% versed into the VMR world :D

https://github.com/dotnet/dotnet/blob/release/10.0.1xx/src/sdk/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets#L58 seems to have the latest changes.

https://github.com/dotnet/dotnet/blob/release/10.0.1xx-rc2-branding-update/src/sdk/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets has old changes, but I'm not sure if that's a shipping branch. cc @mmitche

@mmitche
Copy link
Member

mmitche commented Sep 11, 2025

https://github.com/dotnet/dotnet/blob/release/10.0.1xx-rc2-branding-update/src/sdk/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets has old changes, but I'm not sure if that's a shipping branch. cc @mmitche

Not a shipping branch

@bording
Copy link

bording commented Sep 11, 2025

So, why did the change not end up the RC1 build that shipped? I've checked again by installing dotnet-sdk-10.0.100-rc.1.25451.107-win-x64.exe on a clean VM and the change in this PR is not in the Microsoft.NET.Sdk.FrameworkReferenceResolution.targets file.

Because of that, when I have a multi-targeted project, pruning is not working unless I manually enable it.

Perf regression is correct, but it was only disabled in dotnet/dotnet repo: dotnet/dotnet@2a94fd4.

Is there a plan to re-introduce this in some way before RTM? Is there an issue I can follow?

@nkolev92
Copy link
Contributor Author

Is there a plan to re-introduce this in some way before RTM? Is there an issue I can follow?

The change was only made in the RC1 branch.
RC2 will be built out of release/10.0.1xx branch which doesn't have that revert.

@bording
Copy link

bording commented Sep 11, 2025

Ok, so it was reverted on the RC1 branch before it shipped, but will be back in RC2?

Just curious, is there another change being made to avoid it continuing to cause the perf problem that caused the revert in the first place?

@nkolev92
Copy link
Contributor Author

yes, in a different repo: NuGet/NuGet.Client#6753

@dsplaisted
Copy link
Member

@bording Did your scenario involve pruning for .NET Framework? We've nnow decided to more or less disable pruning for .NET Framework even in the multi-targeted scenario. See #50816 and #50689.

@bording
Copy link

bording commented Sep 15, 2025

@bording Did your scenario involve pruning for .NET Framework? We've nnow decided to more or less disable pruning for .NET Framework even in the multi-targeted scenario. See #50816 and #50689.

I was hit by the changes to pruning between preview 7 and RC1 in pretty much every way possible. I had all of the following scenarios that broke:

  • Multi-targeted projects that are .NET only and include net10.0 (net10.0;net9.0;net8.0)
  • Multi-targeted projects that are .NET only and do not include net10.0 (net9.0;net8.0)
  • Multi-targeted projects that include .NET Framework and include net10.0 (net10;net472)

I ended up spending a lot of time trying to figure out what had happened in RC1 to cause all the broken builds. It would have been nice if the changes had been called out in any of the release notes documents.

Instead, I spent time comparing targets files, and tracking down issues and PRs that might have been related. That's what led me to this PR and my question about why the changes weren't actually in RC1. 😄

@nkolev92
Copy link
Contributor Author

@bording
I am curious to understand the mechanics of the broken builds you've experienced.

In particular, we expect that enabling pruning on/off should not lead to a build break, save for some very special cases.

@bording
Copy link

bording commented Sep 15, 2025

@bording I am curious to understand the mechanics of the broken builds you've experienced.

In particular, we expect that enabling pruning on/off should not lead to a build break, save for some very special cases.

To provide more context, we do set <NuGetAuditMode>all</NuGetAuditMode> and <TreatWarningsAsErrors>true</TreatWarningsAsErrors> in all our repos.

For the first two scenarios I listed, pruning being disabled meant that we were no longer getting pruning of transitive packages that were flagged as vulnerable. We had gone through those repos already as of preview 7 and removed unnecessary direct package references now that pruning was removing them for us.

For the repos that are covered by those scenarios, we had already modified them to build properly when pruning was on, so multi-targeting causing pruning to be disabled in RC1 was a problem for us.

The .NET Framework scenario was also related to vulnerable packages showing back up, but when I tried to fix it by turning pruning back on, I actually hit a runtime error on the net472 version of the program. Turning pruning on for the net472 target caused it to create a binding redirect for System.ValueTuple that couldn't be satisfied.

I know you're already planning on disabling pruning for .NET Framework, and that's also how I solved that problem.


One other thing I've observed while investigating all of this, the NU1903 warnings that are getting reported when building from the commandline aren't quite correct for multi-targeted scenarios. For example, in a net10.0;net472 where I've turned pruning back on manually for just net10.0, just the net472 target has a vulnerable reference, but it's reported for both builds. Is that a known problem or should I open a new issue about it?

@nkolev92
Copy link
Contributor Author

nkolev92 commented Sep 15, 2025

Thanks for the explanation, that was super helpful.

Sorry for all the changes you've had to do, but based on your experiences, this gives me more confidence we have the right solution for the GA version.

The NU1903 issue is not known, so there's probably a bug somewhere.
Can you please file an issue?

@bording
Copy link

bording commented Sep 15, 2025

The NU1903 issue is not known, so there's probably a bug somewhere.
Can you please file an issue?

#50843

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants