Skip to content

Restore's warning and errors calculation uses string alias as a pivot instead of NuGetFramework - #7153

Closed
nkolev92 wants to merge 8 commits into
release/7.3.xfrom
dev-nkolev92-73NoWarnFix
Closed

nkolev92 wants to merge 8 commits into
release/7.3.xfrom
dev-nkolev92-73NoWarnFix

Conversation

@nkolev92

@nkolev92 nkolev92 commented Feb 18, 2026 •

Copy link
Copy Markdown
Member

Bug

Fixes: NuGet/Home#14756

Description

In #6805 and more notably in #6923 a sizable part of the restore core logic was reworked to consider aliases as pivot instead of NuGetFramework.

Turns out that was handled pretty well in most cases, except in scenarios where the TargetFramework element does not actually match the GetShortFolderName of a framework.
In these cases, package specific suppressions do not work.
An example is net10.0-windows frameworks. Maui projects would probably suffer from the same issue as well as the linked issues suggest.

Originally in #6805 and #6923 a large majority of the internal restore infrastructure was changed to use string alias, instead of the NuGetFramework.
Note that this work was done in a way that didn't make intentional functional changes, but simply made changes that are purely internal.
Turns out that it ended up breaking package specific warning suppressions for aliased frameworks such as net10.0-windows. Projects like maui have this issue as well.
The root cause for that is that now all RestoreLogMessage have a target graph that has the alias. Note that this TargetGraphName is shared in many places, so it'll be really hard to understand the impact it'd have if we chnaged it for log messages only.

Workaround: Set the full name of the TargetFramework, so for net10.0-windows set net10.0-windows7.0.

The changes made in the above PRs are like dominos. A lot of changes went on top of those changes, so simply reverting the PR or PRs actually introduces a new risk since there's at least 3-4 other PRs that have now taken dependency on changes so this PR takes it the whole way, in a way that's purely localized to the broken scenario + warning suppression.

Here are some reviewing helpers:

  • 95% of the changes here are going from NuGetFramework to string. Note that PackageSpec.TargetFrameworkInformation already has both, so the changes are straightforward in most places.
  • src/NuGet.Core/NuGet.Commands/RestoreCommand/Logging types are overexposed as public APIs. This change switches from NuGetFramework to string and given that this is something internal, instead of adding more risking by maintaining 2 caches, so we're just gonna make all those types internal (hence the PublicAPI.Shipped.txt changes). Beyond that...
  • src/NuGet.Core/NuGet.Commands/RestoreCommand/Logging/PackageSpecificWarningProperties.cs - only notable change is line 62, where we do a null check for the TargetFrameworkInformation. The method switch from NuGetFramework to alias leads to one that returns a null TFI, while before it returned an empty one. This is really the same behavior as before.
  • src/NuGet.Core/NuGet.Commands/RestoreCommand/Logging/TransitiveNoWarnUtils.cs The only interesting place is the nearest framework calculation on line 115. This one matches by framework, but indexes by alias. This does smell a little bit as I suspect, warnings for project refs coming through ATF won't be suppressed, but project refs with ATF are not super common, so it's why this hasn't been a concern.
  • src/NuGet.Core/NuGet.Commands/RestoreCommand/Logging/WarningPropertiesCollection.cs - In here, the notable change is instead of parsing the first part of the TargetGraphName as NuGetFramework, we treat it as alias.
    Note that for legacy projects, the TargetAlias is "", but the RestoreGraphName has the full target framework name. In order to handle this, we special change when detecting suppressions. Legacy projects always have one framework, so it's safe to just check against that existing framework.

Beyond that, it's all tests really.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@nkolev92
nkolev92 changed the base branch from dev to release/7.3.x February 18, 2026 20:41
@nkolev92 nkolev92 changed the title Dev nkolev92 73 no warn fix Restore's warning and errors calculation uses string alias as a pivot instead of NuGetFramework Feb 19, 2026
@nkolev92

Copy link
Copy Markdown
Member Author

Closing in favor of #7154.

In dev, we'll use this fix, which is being worked on in #7155

@nkolev92 nkolev92 closed this Feb 19, 2026
@nkolev92 nkolev92 mentioned this pull request Feb 20, 2026
3 tasks done
@nkolev92
nkolev92 deleted the dev-nkolev92-73NoWarnFix branch March 16, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NU1701 Warning Not Suppressed by NoWarn="NU1701" on PackageReference (dotnet restore / build)

1 participant