Skip to content

Raise NU1701 for every target framework - #7845

Merged
zivkan merged 1 commit into
NuGet:devfrom
AsadIqbal-Dev:dev-asadiqbal-nu1701-all-frameworks
Nov 4, 2026
Merged

zivkan merged 1 commit into
NuGet:devfrom
AsadIqbal-Dev:dev-asadiqbal-nu1701-all-frameworks

Conversation

@AsadIqbal-Dev

Copy link
Copy Markdown
Contributor

Bug

Fixes: NuGet/Home#14815

Description

LockFileBuilder kept librariesWithWarnings for the whole project, so once a library had NU1701 for the first framework, no other framework got it. This also hid the warning completely in one case: with NoWarn on the package for net10.0, the warning was raised for net10.0 and suppressed, and net9.0 never got one.

The set now tracks (TargetAlias, library), so each framework is checked, and RID graphs of the same framework still don't repeat the warning. The messages are collected and logged after the target loop through the existing DiagnosticUtility.MergeOnTargetGraph, so aliases of the same framework become one message with both target graphs.

One thing to check, because it differs from the skipped test. RestoreCommand_WithAssetTargetFallbackFromProject_WarningsRaisedWhenApplicable expected one message with two target graphs for net10.0 and net9.0. The text of NU1701 names the framework (instead of the project target framework '{2}'), so one message would be wrong for one of the two. I went with one message per framework and changed the test to expect two. Aliases of the same framework have the same text and do merge, which is what the commented out assertion in RestoreCommand_Aliases expected.

If you'd rather have a single message, the text would need to list the frameworks, for example by joining them the way GetFallbackFrameworkString does. A NoWarn on one framework would then leave a message that still names it. I can change it if you prefer that.

Tests:

  • Removed the skip from RestoreCommand_WithAssetTargetFallbackFromProject_WarningsRaisedWhenApplicable and updated it as above.
  • New RestoreCommand_WithAssetTargetFallbackFromProject_NoWarnOnOneFramework_WarningRaisedForTheOther.
  • New RestoreCommand_WithAssetTargetFallbackFromProject_WithRuntimeIdentifier_WarningRaisedOnce, which also passes on dev and guards against repeating the warning for RID graphs.
  • Restored the commented out TargetGraphs assertions in RestoreCommand_Aliases and DotnetRestoreTests.

Without the change, the first two and the RestoreCommand_Aliases test fail.

On net10.0, NuGet.Commands.FuncTest: 289 passed, 2 skipped. I didn't run Dotnet.Integration.Test locally, so the restored assertion in DotnetRestoreTests relies on CI.

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.

LockFileBuilder kept one set of libraries that already had the warning for the whole project, so only the first framework in the project got it. The set is now per target alias, which still avoids repeating the warning for RID graphs. Aliases of the same framework produce the same text, so those are merged into one message with both target graphs.
@AsadIqbal-Dev
AsadIqbal-Dev requested a review from a team as a code owner November 2, 2026 17:42
@dotnet-policy-service dotnet-policy-service Bot added the Community PRs created by someone not in the NuGet team label Nov 2, 2026
@jeffkl
jeffkl requested a balanced review from Copilot November 2, 2026 17:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the change to framework-specific NU1701 warning reporting.

No open issues 🎉

What changed in this PR

This PR fixes NU1701 reporting during restore so that a warning suppressed for one target framework no longer hides warnings for other frameworks.

Changes:

  • Track fallback warnings per target alias and library, while avoiding duplicates for runtime-specific graphs.
  • Merge identical warning messages across aliases of the same framework.
  • Enable and extend regression coverage for multiple frameworks, framework-specific suppression, runtime identifiers, and aliases.
File Description
test/​NuGet.Core.FuncTests/​NuGet.Commands.FuncTest/​RestoreCommandTests.cs Enables multi-framework coverage and adds suppression and runtime-graph tests.
test/​NuGet.Core.FuncTests/​NuGet.Commands.FuncTest/​RestoreCommand_Aliases.cs Restores the assertion that both aliases appear in warning target graphs.
test/​NuGet.Core.FuncTests/​Dotnet.Integration.Test/​DotnetRestoreTests.cs Restores the equivalent alias assertion in CLI integration coverage.
src/​NuGet.Core/​NuGet.Commands/​RestoreCommand/​LockFileBuilder.cs Scopes warning deduplication by alias and merges collected warnings before logging.

Review effort: Balanced

@zivkan
zivkan merged commit cbdebf4 into NuGet:dev Nov 4, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community PRs created by someone not in the NuGet team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When AssetTargetFallback is used twice in the same project, NU1701 is only raised for one framework

5 participants