-
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
warnaserror not failing the build with exit 1 if only errors present were warnings #9825
Comments
This appears to work in the trivial case: <Project>
<Target Name="Build">
<Warning Text="F" />
</Target>
</Project> $ dotnet build /warnaserror
Microsoft (R) Build Engine version 16.1.54-preview+gd004974104 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
S:\repro\dotnet\core-sdk\issues\1708\test.proj(3,3): error : F
Build FAILED.
S:\repro\dotnet\core-sdk\issues\1708\test.proj(3,3): error : F
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.35
$ $LASTEXITCODE
1 Can you tell us more about your repro? What kinds of projects do you have, and how many are in the solution? What target is generating the error? |
Thanks for your response. I will test your trivial case and look at the target and see if we experience the same problem. One obvious difference is we are running dotnet on Linux. |
4 projects in the solution I just discovered that if I run the exact same build without making any other changes I get an intermittnet 1 exit code, here is my exit codes for running the same command and make no other changes. The output is always displayed correctly. $ /dotnet build --no-incremental /WarnAsError
|
@juddgaddie @rainersigwald any news on this issue? This used to work in the past in a consistent way. Is there a workaround maybe? |
I researched various dotnet sdks en think the issue was introduced in the 2.2.2* series/ since msbuild 16.0.450+ga8dc7f1d34: Hopes this helps in tracking down the issue. |
Good to hear its been reproduced independently. I unfortunately haven't made any progress from above. |
In the meantime I tested 3.0-preview7 and it has the same flaky behaviour as previous versions. @richlander I read your blog posts on 3.0-preview and was wondering if you (or dotnet/msbuild team) know about this issue, since I cannot find it on any backlog/roadmap. |
I too have a solution with only warnings. I am building with
I expected the pipeline step to fail with or without "Enable system diagnostics" checked. Is this essentially the same problem that this issue is about or should I create a new issue? |
Oh, maybe this is just the flaky behavior. I will retest later. |
Indeed. Retesting has confirmed that I was just experiencing the previously described flaky behavior. |
@BTSmolders identified 2.2.202 as the earliest SDK he tested that exhibited the bug, but there were more SDKs that could have been tested. I think I have tested all the relevant ones, and I would like to share what I learned.
The git history of tag 2.1.602 has no parallel branches at tag v2.1.500. The released SDKs between those two tags form two parallel branches: the "2.1.600-preview-009426 branch" and the "2.1.50X branch". The last 2.1.50X release before the release of 2.1.602 was 2.1.506. In summary, I think the bug was introduced somewhere before 2.1.602 and after 2.1.600-preview-009426 and 2.1.506. I tested all these SDKs on Azure DevOps using the Use .NET Core task. |
We have this issue all the time with .NET Core 3.1.200 building in Azure DevOps, which makes harder to review PR (you can't rely in the build result but actually go and check the build task). Should this issue be moved to the dotnet/sdk (before dotnet/cli) repository? Maybe there it can be tracked better and it doesn't look a problem of installation. |
I was able to reproduce it here: I am not sure if it happened by accident, but this repo started to show the behavior when the only warning started with |
Hello,
after that dotnet build task considered as failed for first build attempt and all subsequent attempts. also be sure that don't used sinarqube prepare task before build
|
We're facing this issue exactly as described. When all of our errors are derived from warnings, msbuild only intermittently exits with an error (exit code 1). So sometimes the build task passes, and sometimes it doesn't. The desired behavior is that we fail the task when "warnings as errors" is enabled, every time, consistently. We use this for enhanced code analysis when we have pull requests targeting master. We have a significant amount of code churn and we need an automated solution. Intermittent behavior obviously makes this difficult. This is our current pipeline YAML: branches: pr: pool: steps:
We've tried setting "-p:TreatWarningsAsErrors=true" alone, "-warnaserror" alone, and a combination of the two. We never get consistent results. Please advise. |
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
I haven't noticed this approach exhibiting the bug described in this issue. |
This is exactly the behavior I want as well. It's just really unfortunate we have to use a workaround, instead of just having the feature working as expected. Thanks for pointing out the workaround, though! 👍 |
So, is there any progress on this? |
dotnet core build does not fail azure devops build when -WarnAsErrorhaving this issue now too. build errors created with -WarnAsError and/or TreatWarningsAsErrors=true adding TreatWarningsAsErrors to project files makes no difference in behavior. |
Update: I have since found if building using msbuild instead of dotnet, TreatWarningsAsErrors does work as expected. |
I encountered this issue also. Here is the workaround I used:
The |
I filed a related issue against msbuild, a few months ago. I use /graph:true as a workaround. It reliably reproduces the error. |
How is this actually a workaround? Applying it only to your build server should mean that only your build server will get this behaviour; the one on which intermittent behaviour is crucial. |
I have been using this solution for six months now, and it is continuing to work perfectly. I think we have a misunderstanding. You seem to not understand my workaround for my use case, and I don't know what it is about my workaround that you don't understand. Can you elaborate about confusion? I will do my best to clarify my original comment that you quoted. |
This was likely resolved by #6174, is anyone still seeing this? Edit: It should be available as early as VS16.10 preview 1 |
I just got it today with .net 6 :( |
Happening still. |
Still happening in 6.0.401. |
Old issue triage: Ben thought he fixed it in msbuild but there were later report so moving over for analysis. |
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.
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
The text was updated successfully, but these errors were encountered: