-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MSBuildTreatWarningsAsErrors does not integrate with WarningsNotAsErrors well - project vs solution #10801
Comments
In Visual Studio, it's remains a warning. |
What I know so far: I can repro on Windows with dotnet/templating@33a8ecb. The errors come when building with I canNOT repro with <Project>
<PropertyGroup>
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
<MSBuildWarningsNotAsErrors>ABC123</MSBuildWarningsNotAsErrors>
</PropertyGroup>
<Target Name="Dispatch">
<ItemGroup>
<P Include="$(MSBuildThisFileFullPath)" AdditionalProperties="Num=1" />
<P Include="$(MSBuildThisFileFullPath)" AdditionalProperties="Num=2" />
<P Include="$(MSBuildThisFileFullPath)" AdditionalProperties="Num=3" />
<P Include="$(MSBuildThisFileFullPath)" AdditionalProperties="Num=4" />
</ItemGroup>
<MSBuild Projects="@(P)" BuildInParallel="true" Targets="Warn" />
</Target>
<Target Name="Warn">
<Warning Code="ABC123" Text="Hello from instance $(Num) in pid $([System.Diagnostics.Process]::GetCurrentProcess().Id)" />
<Exec Command="sleep 1" /><!-- To give worker nodes some time to spin up -->
</Target>
</Project> Which seems like exactly the same thing. I want to debug into that now to see how it's different. |
In the success case in, msbuild/src/Build/BackEnd/Components/Logging/LoggingService.cs Lines 1994 to 2003 in 69b3e7a
|
Aha! The templating ❯ dotnet msbuild -m .\foo.csproj /warnaserror
foo succeeded with 1 warning(s) (0.0s)
C:\Users\raines\Downloads\foo.csproj(19,5): warning ABC123: Hello from instance 1 in pid 39896
foo succeeded (0.0s)
C:\Users\raines\Downloads\foo.csproj(19,5): error ABC123: Hello from instance 4 in pid 3804
foo succeeded (0.0s)
C:\Users\raines\Downloads\foo.csproj(19,5): error ABC123: Hello from instance 3 in pid 5872
foo succeeded (0.0s)
C:\Users\raines\Downloads\foo.csproj(19,5): error ABC123: Hello from instance 2 in pid 8016
Build failed with 3 error(s) and 1 warning(s) in 0.2s |
Looks like c1d088e alllllmost fixed this but scoped it to when buildchecks are enabled. Removing that part of the condition, it works. |
For the single-proc case from the OP where projects (or <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>$(WarningsNotAsErrors);NU1603</WarningsNotAsErrors>
In this case, MSBuild elevates the errors because it only pays attention to If we add that: <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>$(WarningsNotAsErrors);NU1603</WarningsNotAsErrors>
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
[b] is caused by the multitargeting project not importing common.targets, and thus not importing the adopt-unprefixed-warning-tweaks-to-MSBuild-prefixed ones (#10873). Working around that with <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>$(WarningsNotAsErrors);NU1603</WarningsNotAsErrors>
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
<MSBuildWarningsNotAsErrors>$(WarningsNotAsErrors)</MSBuildWarningsNotAsErrors>
[c] is because MSBuild is configured overall to promote warnings, and does so for the warning raised by NuGet in the solution metaproject. That project doesn't import Dropping a <Project>
<PropertyGroup>
<MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
<MSBuildWarningsNotAsErrors>NU1603</MSBuildWarningsNotAsErrors>
</PropertyGroup>
</Project>
Hooray! But wait, what if things happen out of proc? Let's force that with
That fails [d] because of #10874 that I identified above. |
Issue Description
Take the following project:
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
Expected Behavior
Actual Behavior
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).
The text was updated successfully, but these errors were encountered: