Repository navigation
Restore's warning and errors calculation uses string alias as a pivot instead of NuGetFramework - #7155
Merged
Conversation
… instead of NuGetFramework
3 tasks done
nkolev92
marked this pull request as ready for review
February 20, 2026 23:15
jeffkl
self-requested a review
February 24, 2026 23:44
jeffkl
previously approved these changes
Feb 25, 2026
Contributor
There was a problem hiding this comment.
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
TargetGraphNameas 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
EqualscomparesProjectFrameworksusingStringComparer.OrdinalIgnoreCase, butGetHashCodecurrently useshashCode.AddSequence(ProjectFrameworks), which relies onstring.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 withStringComparer.OrdinalIgnoreCase).
public override int GetHashCode()
{
var hashCode = new HashCodeCombiner();
hashCode.AddObject(ProjectWideWarningProperties);
hashCode.AddObject(PackageSpecificWarningProperties);
hashCode.AddSequence(ProjectFrameworks);
jeffkl
approved these changes
Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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
Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.