-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Suppress CS8002 warning for modern .NET TFMs #51169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.CSharp.targets
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot redo this work. you expanded the scope beyond what was requested - only on modern .NET (so TargetFramework values that are netx.y
and compatible) should the CS8002 NoWarn value be added.
Changed the condition from _IsNETCoreOrNETStandard to only check TargetFrameworkIdentifier == '.NETCoreApp'. This ensures CS8002 is only suppressed for modern .NET (net6.0, net7.0, net8.0, etc.) and NOT for .NETStandard. Updated tests to verify netstandard2.0 and netstandard2.1 are NOT suppressed. Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
I've corrected the implementation to only suppress CS8002 for modern .NET TFMs (netx.y format). The change now uses |
Use $(TargetFrameworkIdentifier) if possible, so that it works properly with custom TargetFramework aliases. However I don't know whether the TargetFrameworkIdentifier property has already been set by the time this code is evaluated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this work should happen in the sdk but instead directly in Microsoft.CSharp.Core.targets
. There are already platform specific NoWarn
suppressions there and this would fit in with them.
Summary
The SDK now automatically suppresses the CS8002 warning (referenced assembly doesn't have a strong name) for C# projects targeting modern .NET TFMs (netx.y format like net6.0, net7.0, net8.0). This warning is irrelevant on modern .NET runtimes where strong-name validation has been removed, and was creating noise for users.
Changes
Modified
Microsoft.NET.Sdk.CSharp.targets
to append CS8002 to theNoWarn
property when the project targets .NETCoreApp (modern .NET), using theTargetFrameworkIdentifier
check for detection.The suppression is applied automatically by the SDK and requires no action from users. Projects targeting .NET Framework and .NET Standard are unaffected and will continue to receive CS8002 warnings if applicable.
Examples
Before this change:
After this change:
Testing
Added comprehensive tests in
GivenThatWeWantToSuppressCS8002Warning.cs
that verify:All tests pass successfully.
Fixes #43206
Related to dotnet/roslyn#76197
Fixes #51168
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.