WarningsNotAsErrors does not prevent NU1605 from becoming an error
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
@segor commented on [Thu, 06 Aug 2026 11:14:52 GMT](https://github.com/NuGet/Home/issues/15024)
### 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:
```xml
net48
true
NU1605
```
2. Run:
```powershell
dotnet restore .\NuGetWarningsNotAsErrorsRepro.csproj --source https://api.nuget.org/v3/index.json
```
Or, from a Visual Studio Developer PowerShell/Command Prompt:
```powershell
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:
```text
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
```shell
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)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.