Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 8, 2025

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 the NoWarn property when the project targets .NETCoreApp (modern .NET), using the TargetFrameworkIdentifier 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:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <!-- Users had to manually add CS8002 to suppress the warning -->
    <NoWarn>$(NoWarn);CS8002</NoWarn>
  </PropertyGroup>
</Project>

After this change:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <!-- CS8002 is now automatically suppressed for modern .NET -->
  </PropertyGroup>
</Project>

Testing

Added comprehensive tests in GivenThatWeWantToSuppressCS8002Warning.cs that verify:

  • CS8002 is suppressed for net6.0, net7.0, and net8.0
  • CS8002 is NOT suppressed for net472, net48, netstandard2.0, and netstandard2.1
  • CS8002 suppression works correctly alongside existing NoWarn values

All tests pass successfully.

Fixes #43206

Related to dotnet/roslyn#76197

Fixes #51168

Original prompt

This section details on the original issue you should resolve

<issue_title>The SDK should suppress strong-name checking (CS8002) when targeting .NET TFMs</issue_title>
<issue_description>### Is your feature request related to a problem? Please describe.
The CS8002 warning (referenced assembly doesn't have a strong name) is irrelevant on modern .NET runtimes - all such checks have been removed from the runtime. As a result any such diagnostics are noise to users.

Describe the solution you'd like

The SDK should detect when C# is the project language and the TFM is a .NET Core TFM and append CS8002 to the existing NoWarn list if able in its MSBuild Targets.

Additional context

Related to dotnet/roslyn#76197.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #51168

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Suppress strong-name checking warning for .NET TFMs Suppress CS8002 warning for .NET Core and .NET Standard TFMs Oct 8, 2025
@Copilot Copilot AI requested a review from baronfel October 8, 2025 15:50
Copilot finished work on behalf of baronfel October 8, 2025 15:50
Copy link
Member

@baronfel baronfel left a 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>
Copy link
Contributor Author

Copilot AI commented Oct 8, 2025

@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.

I've corrected the implementation to only suppress CS8002 for modern .NET TFMs (netx.y format). The change now uses TargetFrameworkIdentifier == '.NETCoreApp' instead of _IsNETCoreOrNETStandard, so CS8002 is suppressed for net6.0, net7.0, net8.0, etc., but NOT for .NETStandard or .NET Framework. Tests updated accordingly. (commit 4e8b716)

@Copilot Copilot AI changed the title Suppress CS8002 warning for .NET Core and .NET Standard TFMs Suppress CS8002 warning for modern .NET TFMs Oct 8, 2025
@Copilot Copilot AI requested a review from baronfel October 8, 2025 16:12
Copilot finished work on behalf of baronfel October 8, 2025 16:12
@KalleOlaviNiemitalo
Copy link
Contributor

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.

Copy link
Member

@jaredpar jaredpar left a 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.

Example: https://github.com/dotnet/roslyn/blob/adaf4f7c7d9b4dfa68a397208fc05dfdd0e2d08f/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets#L65-L67

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.

4 participants