Repository navigation
Description
@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.
- Create
NuGetWarningsNotAsErrorsRepro.csprojwith 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>- Run:
dotnet restore .\NuGetWarningsNotAsErrorsRepro.csproj --source https://api.nuget.org/v3/index.jsonOr, from a Visual Studio Developer PowerShell/Command Prompt:
msbuild .\NuGetWarningsNotAsErrorsRepro.csproj /t:Restore /p:RestoreSources=https://api.nuget.org/v3/index.json /v:minimalExpected: 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
jebriede commentedon Aug 10, 2026
@martinrrm commented on Sat, 08 Aug 2026 00:37:52 GMT
Could be related to #37972, but user is using
TreatWarningsAsErrorsjebriede commentedon Aug 10, 2026
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.
github-actions commentedon Aug 10, 2026
🎯 Agentic Issue Triage
Triage Assessment:
@nkolev92|@dotnet/nuget-teamhigh- Issue directly identifiesMicrosoft.NET.Sdk.CSharp.propsadding NU1605 to WarningsAsErrors, clearly Area-NuGet.➡️ Summary:
WarningsNotAsErrorscannot override NU1605 because the SDK appends it toWarningsAsErrorsinMicrosoft.NET.Sdk.CSharp.props. Investigate removing NU1605 from the SDK-injectedWarningsAsErrorsor givingWarningsNotAsErrorshigher precedence.zivkan commentedon Aug 11, 2026
@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>segor commentedon Aug 11, 2026
Thanks, it worked for me.
2 remaining items
baronfel commentedon Aug 11, 2026
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.
nkolev92 commentedon Aug 26, 2026
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.