Description
Example code: https://github.com/aaron-tyler-ds/-MSB3245
We have a chunk of code where we're forcing several msbuild warnings to be promoted to errors. We're seeing that this inconsistently causes dotnet build
to return a exit code of 0 even though the build failed. I've distilled an example down to the repo mentioned at the start of this issue.
Example output. Note that the MSB3245 hit shows up as an error, and the summary view correctly lists 1 error, but the process exit code was still 0.
C:\repos\MSB3277\src\exe>dotnet build
Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Restored C:\repos\MSB3277\src\classlib1\classlib1.csproj (in 124 ms).
Restored C:\repos\MSB3277\src\classlib2\classlib2.csproj (in 124 ms).
Restored C:\repos\MSB3277\src\classlib3\classlib3.csproj (in 124 ms).
Restored C:\repos\MSB3277\src\exe\exe.csproj (in 124 ms).
classlib1 -> C:\repos\MSB3277\src\classlib1\bin\Debug\net47\classlib1.dll
classlib2 -> C:\repos\MSB3277\src\classlib2\bin\Debug\net47\classlib2.dll
classlib3 -> C:\repos\MSB3277\src\classlib3\bin\Debug\net47\classlib3.dll
C:\Program Files\dotnet\sdk\3.1.403\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB3245: Could not resolve this reference. Could not locate the assembly "FooBar.Baz". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\repos\MSB3277\src\exe\exe.csproj]
exe -> C:\repos\MSB3277\src\exe\bin\Debug\net47\exe.exe
Build succeeded.
C:\Program Files\dotnet\sdk\3.1.403\Microsoft.Common.CurrentVersion.targets(2084,5): error MSB3245: Could not resolve this reference. Could not locate the assembly "FooBar.Baz". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\repos\MSB3277\src\exe\exe.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.06
C:\repos\MSB3277\src\exe>echo %errorlevel%
0
Interestingly, when this project doesn't have ProjectReferences
to other projects this occurs much less frequently.
The nonzero exit code breaks our automated build process. We've also seen other versions of this, where the process exit code is 1 but there are no errors listed, however I don't have a consistent repro of this behavior but it feels related.