Skip to content

WarningsNotAsErrors does not prevent NU1605 from becoming an error #55709

Open

Description

@jebriede

@segor commented on Thu, 06 Aug 2026 11:14:52 GMT

NuGet Product Used

dotnet.exe

Product Version

dotnet SDK 8.0.423 and 9.0.316; Visual Studio 2022 MSBuild 17.14.51.32402 on Windows.

Worked before?

No known working version.

Impact

It's more difficult to complete my work

Repro Steps & Context

Setting WarningsNotAsErrors to NU1605 does not prevent NU1605 from being elevated to an error when TreatWarningsAsErrors=true.

This is not a request to suppress the downgrade. The desired behavior is to keep NU1605 visible as a warning while allowing restore/build to continue.

  1. Create NuGetWarningsNotAsErrorsRepro.csproj with this content:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <WarningsNotAsErrors>NU1605</WarningsNotAsErrors>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="114.0.0" />
    <PackageReference Include="System.Text.Json" Version="8.0.5" />
  </ItemGroup>
</Project>
  1. Run:
dotnet restore .\NuGetWarningsNotAsErrorsRepro.csproj --source https://api.nuget.org/v3/index.json

Or, from a Visual Studio Developer PowerShell/Command Prompt:

msbuild .\NuGetWarningsNotAsErrorsRepro.csproj /t:Restore /p:RestoreSources=https://api.nuget.org/v3/index.json /v:minimal

Expected: restore succeeds and logs NU1605 as a warning, because NU1605 is listed in WarningsNotAsErrors.

Actual: restore fails with NU1605: Warning As Error.

The generated NuGet restore graph confirms this is not an MSBuild import/order problem. Its warning properties contain all three of the following values:

allWarningsAsErrors: true
warnAsError: [NU1605]
warnNotAsError: [NU1605]

WarningsNotAsErrors therefore reaches NuGet, but does not take precedence for NU1605.

Diagnostic observation: Microsoft.NET.Sdk.CSharp.props appends NU1605 to WarningsAsErrors. This puts NU1605 in both WarningsAsErrors and WarningsNotAsErrors; restore currently gives the former precedence.

Temporary workaround: adding -p:WarningsAsErrors= to the restore command prevents that SDK-added entry. Restore then succeeds and emits NU1605 as a warning while TreatWarningsAsErrors=true and WarningsNotAsErrors=NU1605 remain set.

Additional context: this appears related to NuGet/Home#5375, which introduced WarningsNotAsErrors for warnings elevated by TreatWarningsAsErrors.

The result was reproduced with .NET SDKs 8.0.423 and 9.0.316 and Visual Studio 2022 MSBuild 17.14.51.32402.

Verbose Logs

This is a compact sanitized summary. The full detailed and diagnostic restore logs exceed the GitHub issue form's 65,536-character limit and are available on request.

Command:
dotnet restore .\NuGetWarningsNotAsErrorsRepro.csproj --source https://api.nuget.org/v3/index.json --verbosity diag

Environment:
.NET SDK: 9.0.316
MSBuild: 17.14.43+2a0eb78b3
NuGet client assemblies: 6.14.3.1
Target framework: net48
Feed: https://api.nuget.org/v3/index.json

Effective MSBuild properties:
TreatWarningsAsErrors = true
WarningsAsErrors = ;NU1605
WarningsNotAsErrors = NU1605

Generated NuGet restore graph warning properties:
allWarningsAsErrors: true
warnAsError: [NU1605]
warnNotAsError: [NU1605]

Restore result:
error NU1605: Warning As Error: Detected package downgrade: System.Text.Json from 10.0.0 to 8.0.5. Reference the package directly from the project to select a different version.
error NU1605: NuGetWarningsNotAsErrorsRepro -> RestSharp.Serializers.NewtonsoftJson 114.0.0 -> RestSharp 114.0.0 -> System.Text.Json (>= 10.0.0)
error NU1605: NuGetWarningsNotAsErrorsRepro -> System.Text.Json (>= 8.0.5)

Activity

  1. jebriede commented on Aug 10, 2026

    @jebriede
    Author

    @martinrrm commented on Sat, 08 Aug 2026 00:37:52 GMT
    Could be related to #37972, but user is using TreatWarningsAsErrors

  2. added
    untriaged
    on Aug 10, 2026
  3. jebriede commented on Aug 10, 2026

    @jebriede
    Author

    The issue the customer is experiencing is that the NU1605 is treated as an Error by the SDK. During a NuGet team triage meeting we weren't sure why it's being treated as an error. This prevents the customer from deciding if the warning should be an error or not.

  4. locked and limited conversation to collaborators on Aug 10, 2026
  5. unlocked this conversation on Aug 10, 2026
  6. added
    cookie
    and removed
    untriaged
    on Aug 10, 2026
  7. github-actions commented on Aug 10, 2026

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Triage Assessment:

    • 🏷️ Labels: Area-NuGet Bug cookie Issue Monster Loves Cookies!
    • 💻 Assignment: @nkolev92 | @dotnet/nuget-team
    • 🟩 Confidence: high - Issue directly identifies Microsoft.NET.Sdk.CSharp.props adding NU1605 to WarningsAsErrors, clearly Area-NuGet.

    Similar issues: #37972 (duplicate)

    ➡️ Summary: WarningsNotAsErrors cannot override NU1605 because the SDK appends it to WarningsAsErrors in Microsoft.NET.Sdk.CSharp.props. Investigate removing NU1605 from the SDK-injected WarningsAsErrors or giving WarningsNotAsErrors higher precedence.

    Generated by 🏷️ Issue Triage for #55709 · 36.8 AIC · ⌖ 4.82 AIC · ⊞ 10.1K · ◷

  8. zivkan commented on Aug 11, 2026

    @zivkan
    Member

    @segor as long as the SDK keeps adding NU1605 to WarningsAsErrors, you can mitigate it by removing it with something like this: <WarningsAsErrors>$(WarningsAsErrors.Replace('NU1605', ''))</WarningsAsErrors>

  9. segor commented on Aug 11, 2026

    @segor

    @segor as long as the SDK keeps adding NU1605 to WarningsAsErrors, you can mitigate it by removing it with something like this: <WarningsAsErrors>$(WarningsAsErrors.Replace('NU1605', ''))</WarningsAsErrors>

    Thanks, it worked for me.

  10. 2 remaining items

  11. added
    untriaged
    on Aug 11, 2026
  12. baronfel commented on Aug 11, 2026

    @baronfel
    Member

    I found the original SDK change: #1329, and a subsequent tweak in #3645.

    I think this was done in part because NuGet at the time didn't support WarningsNotAsErrors, which was implemented in NuGet/NuGet.Client#4846 for .NET SDK 7.0.200.

    I think given that NuGet supports the more 'general' flagging, we can change this behavior in the SDK and remove the forceful-upgrade.

  13. added and removed
    untriaged
    on Aug 11, 2026
  14. added theissue type on Aug 11, 2026
  15. added this to the 11.0.1xx milestone on Aug 11, 2026
  16. nkolev92 commented on Aug 26, 2026

    @nkolev92
    Contributor

    I think given that NuGet supports the more 'general' flagging, we can change this behavior in the SDK and remove the forceful-upgrade.

    I'm not sure I follow this.

    The PR in #55732, basically makes NU1605 just a warning and would be really, really impactful as far as restore goes and would change a lot about what a legal restore graph is.

  17. added
    needs team triage
    and removed
    needs team triage
    on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area-NetSDKcookie

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions