MSBuildTreatWarningsAsErrors does not integrate with WarningsNotAsErrors well - project vs solution
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
### Issue Description
Take the following project:
```xml
net472
enable
enable
true
$(WarningsNotAsErrors);NU1603
true
```
The expectation would be that when restore is run on this project, NU1603 is raised, and because of TreatWarningsAsErrors and WarningsNotAsErrors, it'd remain a warning.
Now if you specify the project file, it errors, if you don't specify the project file, it warns.
After some investigation, it seems like it's a solution vs project thing.
I have validated that NuGet does the same thing in both cases. After all, NuGet does not depend on MSBuildTreatWarningsAsErrors.
### Steps to Reproduce
I have a repro attached that demonstrates the behavior.
Extract the project and run the `run.ps1` script.
[Warnings-Update.zip](https://github.com/user-attachments/files/17347324/Warnings-Update.zip)
### Expected Behavior
```console
Running outside of the project folder
Running -t:restore src/Warnings.csproj
MSBuild version 17.13.0-preview-24504-04+c4d51a11b for .NET Framework
C:\Code\Warnings\src\Warnings.csproj : warning NU1603: Warnings depends on NuGet.Common (>= 6.10.10) but NuGet.Common 6.10.10 was not found. NuGet.Common 6.11.0 was resolved instead.
Running -t:restore src/
MSBuild version 17.13.0-preview-24504-04+c4d51a11b for .NET Framework
C:\Code\Warnings\src\Warnings.csproj : warning NU1603: Warnings depends on NuGet.Common (>= 6.10.10) but NuGet.Common 6.10.10 was not found. NuGet.Common 6.11.0 was resolved instead. [C:\Code\Warnings\src\War
nings.sln]
Running in the project folder
Running -t:restore Warnings.csproj
MSBuild version 17.13.0-preview-24504-04+c4d51a11b for .NET Framework
C:\Code\Warnings\src\Warnings.csproj : warning NU1603: Warnings depends on NuGet.Common (>= 6.10.10) but NuGet.Common 6.10.10 was not found. NuGet.Common 6.11.0 was resolved instead.
Running -t:restore
MSBuild version 17.13.0-preview-24504-04+c4d51a11b for .NET Framework
C:\Code\Warnings\src\Warnings.csproj : warning NU1603: Warnings depends on NuGet.Common (>= 6.10.10) but NuGet.Common 6.10.10 was not found. NuGet.Common 6.11.0 was resolved instead. [C:\Code\Warnings\src\War
nings.sln]
```
### Actual Behavior
```console
Running outside of the project folder
Running -t:restore src/Warnings.csproj
MSBuild version 17.13.0-preview-24504-04+c4d51a11b for .NET Framework
C:\Code\Warnings\src\Warnings.csproj : error NU1603: Warnings depends on NuGet.Common (>= 6.10.10) but NuGet.Common 6.10.10 was not found. NuGet.Common 6.11.0 was resolved instead.
Running -t:restore src/
MSBuild version 17.13.0-preview-24504-04+c4d51a11b for .NET Framework
C:\Code\Warnings\src\Warnings.csproj : warning NU1603: Warnings depends on NuGet.Common (>= 6.10.10) but NuGet.Common 6.10.10 was not found. NuGet.Common 6.11.0 was resolved instead. [C:\Code\Warnings\src\War
nings.sln]
Running in the project folder
Running -t:restore Warnings.csproj
MSBuild version 17.13.0-preview-24504-04+c4d51a11b for .NET Framework
C:\Code\Warnings\src\Warnings.csproj : error NU1603: Warnings depends on NuGet.Common (>= 6.10.10) but NuGet.Common 6.10.10 was not found. NuGet.Common 6.11.0 was resolved instead.
Running -t:restore
MSBuild version 17.13.0-preview-24504-04+c4d51a11b for .NET Framework
C:\Code\Warnings\src\Warnings.csproj : warning NU1603: Warnings depends on NuGet.Common (>= 6.10.10) but NuGet.Common 6.10.10 was not found. NuGet.Common 6.11.0 was resolved instead. [C:\Code\Warnings\src\War
nings.sln]
```
### Analysis
🤷
### Versions & Configurations
17.12, 17.8 seem to have the same way as 17.13.
We do expect an influx of WarningsNotAsErrors though, since that's part of the recommendation for audit warnings (the original way we noticed this issue).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.