MSBuildTreatWarningsAsErrors doesn't work in Visual Studio builds
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 139
Description
In Visual Studio, I can add the property MSBuildTreatWarningsAsErrors and set it to true:
```
Exe
net6.0
enable
enable
true
```
I notice that in a build, the output text changes from “warning CS0168” to “error CS0168”:
```
1>C:\Users\ghogen\source\repos\ConsoleApp4\ConsoleApp4\Program.cs(3,5,3,6): error CS0168: The variable 'i' is declared but never used
1>ConsoleApp4 -> C:\Users\ghogen\source\repos\ConsoleApp4\ConsoleApp4\bin\Debug\net6.0\ConsoleApp4.dll
1>Done building project "ConsoleApp4.csproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
```
However, the build is not failed. It is still marked as succeeded. Shouldn’t the build have failed? Is there another property or command-line switch to set to fail the build.
From the command line, the same build FAILS.
```
msbuild ConsoleApp4.csproj
Done Building Project "c:\Users\ghogen\source\repos\ConsoleApp4\ConsoleApp4\ConsoleApp4.csproj" (default targets).
Build FAILED.
"c:\Users\ghogen\source\repos\ConsoleApp4\ConsoleApp4\ConsoleApp4.csproj" (default target) (1) ->
(CoreCompile target) ->
c:\Users\ghogen\source\repos\ConsoleApp4\ConsoleApp4\Program.cs(3,5): error CS0168: The variable 'i' is declared but
never used [c:\Users\ghogen\source\repos\ConsoleApp4\ConsoleApp4\ConsoleApp4.csproj]
0 Warning(s)
1 Error(s)
```
VS should have the same result as the command-line build of the same project.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.