Skip to content

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

Merged
nkolev92 merged 6 commits into
devfrom
dev-nkolev92-nowarnfix
Feb 25, 2026
Merged

nkolev92 merged 6 commits into
devfrom
dev-nkolev92-nowarnfix

Conversation

@nkolev92

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.

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 marked this pull request as ready for review February 20, 2026 23:15
@nkolev92
nkolev92 requested a review from a team as a code owner February 20, 2026 23:15
@jeffkl
jeffkl self-requested a review February 24, 2026 23:44
jeffkl
jeffkl previously approved these changes Feb 25, 2026

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.

Pull request overview

Fixes restore warning/error suppression behavior for aliased target frameworks by pivoting package-specific warning properties off string target aliases (instead of NuGetFramework), ensuring suppressions work even when TargetFramework strings don’t match GetShortFolderName() (e.g., net10.0-windows vs net10.0-windows7.0).

Changes:

  • Switch restore warning-property plumbing to use target alias strings for indexing/matching (and make previously overexposed logging types internal).
  • Update warning suppression logic to interpret TargetGraphName as alias-first and add legacy/special-case handling.
  • Add/adjust unit + functional + dotnet integration tests covering alias-based suppressions and project-reference scenarios.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/TestUtilities/Test.Utility/Commands/ProjectTestHelpers.cs Preserve project-wide warning properties when cloning test specs.
test/NuGet.Core.Tests/NuGet.Commands.Test/WarningPropertiesCollectionTests.cs Update tests to use framework/alias strings rather than NuGetFramework.
test/NuGet.Core.Tests/NuGet.Commands.Test/TransitiveNoWarnUtilsTests.cs Update transitive no-warn tests to use alias strings and case-insensitive dictionaries.
test/NuGet.Core.Tests/NuGet.Commands.Test/PackageSpecificWarningPropertiesTests.cs Update package-specific no-warn tests to validate alias-based behavior.
test/NuGet.Core.Tests/NuGet.Commands.Test/CollectorLoggerTests.cs Update collector logger tests for alias-based APIs and internal visibility changes.
test/NuGet.Core.FuncTests/NuGet.Commands.FuncTest/RestoreCommand_Aliases.cs Add functional coverage for conditional suppressions with aliases and project references.
test/NuGet.Core.FuncTests/NuGet.Commands.FuncTest/RestoreCommandTests.cs Add functional tests ensuring suppressions work with aliased frameworks (e.g., net10.0-windows).
test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetRestoreTests.cs Add dotnet restore integration test for alias-based package-specific suppression.
src/NuGet.Core/NuGet.Commands/RestoreCommand/Logging/WarningPropertiesCollection.cs Core suppression logic updated to use alias strings and parse alias from target graph name.
src/NuGet.Core/NuGet.Commands/RestoreCommand/Logging/TransitiveNoWarnUtils.cs Update transitive no-warn extraction/indexing to operate on alias strings.
src/NuGet.Core/NuGet.Commands/RestoreCommand/Logging/RestoreCollectorLogger.cs Use alias strings for project frameworks and internalize warning-collection properties.
src/NuGet.Core/NuGet.Commands/RestoreCommand/Logging/PackageSpecificWarningProperties.cs Store package-specific no-warn properties keyed by alias strings; add null-safe TFI lookup.
src/NuGet.Core/NuGet.Commands/PublicAPI/net8.0/PublicAPI.Shipped.txt Remove restore logging types from public API surface (made internal).
src/NuGet.Core/NuGet.Commands/PublicAPI/net472/PublicAPI.Shipped.txt Same public API surface adjustments for net472.
src/NuGet.Core/NuGet.Commands/GlobalSuppressions.cs Remove suppressions tied to APIs no longer externally visible.
Comments suppressed due to low confidence (1)

src/NuGet.Core/NuGet.Commands/RestoreCommand/Logging/WarningPropertiesCollection.cs:191

  • Equals compares ProjectFrameworks using StringComparer.OrdinalIgnoreCase, but GetHashCode currently uses hashCode.AddSequence(ProjectFrameworks), which relies on string.GetHashCode() (case-sensitive). This can violate the Equals/GetHashCode contract when aliases differ only by case and may break dictionary/hash-set usage. Update hashing to use a case-insensitive comparer for each framework string (e.g., add each item with StringComparer.OrdinalIgnoreCase).
        public override int GetHashCode()
        {
            var hashCode = new HashCodeCombiner();

            hashCode.AddObject(ProjectWideWarningProperties);
            hashCode.AddObject(PackageSpecificWarningProperties);
            hashCode.AddSequence(ProjectFrameworks);

@nkolev92
nkolev92 requested a review from jeffkl February 25, 2026 21:35
@nkolev92
nkolev92 enabled auto-merge (squash) February 25, 2026 21:35
@jeffkl
jeffkl requested a review from Copilot February 25, 2026 21:40

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.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

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)

3 participants