question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

warnaserror not failing the build with exit 1 if only errors present were warnings

See original GitHub issue

When there are no errors in a build, but only warnings that have been promoted to error with WarnAsError then the build will not fail with an exit of 1.

$ dotnet build --no-incremental /WarnAsError

...

Build FAILED.

....cs(28,1): error SA1507: Code must not contain multiple blank lines in a row [....csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.55
Exit code =>  0

Given that there are errors in the build, would expect an exit code of 1

Note that if there are genuine errors in the build, the build will fail correctly with the correct exit code

OS: Linux Ubuntu 18.04 dotnet version: 2.2.3-preview

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:13
  • Comments:29 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
mungojamcommented, Feb 10, 2022

I just got it today with .net 6 😦

3reactions
TysonMNcommented, Sep 15, 2020

I thought of a good workaround that I am now using in my application at work.

The behavior I want is to allow warnings on developer machines but treat warnings as errors on our build server. The configuration on a developer machine is Debug and the configuration on the build server is Release. Therefore, doing this in each project files achieves the behavior that I want.

<PropertyGroup Condition="'$(Configuration)' != 'Debug'">
  <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

I haven’t noticed this approach exhibiting the bug described in this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fetch warnings from the dotnet build command
1 Answer 1 ... What you can do is simply add /WarnAsError to your dotnet build. ... EDIT: OP requested to not fail...
Read more >
C# Compiler Options to report errors and warnings
C# Compiler Options for errors and warnings. These options suppress or enable warnings, and control warnings as errors.
Read more >
Version History
•When the build process of a project was failing due to missing resources or other resource related problems, then the error list was...
Read more >
Nuget restore - system cannot find file - Microsoft.Build. ...
Everytime I try to run Nuget restore I get this error. I get on another server that I am trying to put a...
Read more >
Troubleshooting F# | F# for fun and profit
A number of errors can be caused by this, such as “FS0072: Lookup on object of indeterminate type” and “FS0041: A unique overload...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found