-
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
Add a "treat warnings as errors" option #68
Comments
Thanks for the suggestion, sounds like a potentially useful feature. This doesn't meet the bar for our roadmap at this time however. |
Is there a Roadmap defined somewhere? |
If it is a potentially useful feature, why is the issue closed? Someone from the community may want to pick it up. |
As a work around, you should be (I think) able to add TreatWarningsAsErrors property in a targets file - set it to true and invoke that target as a part of the msbuild command line argument along with your default targets. Wouldn't that work? |
@chandramouleswaran: that's for the compiler warnings, not for warnings from MSBuild itself. I want to be able to make things like missing files be errors, not warnings like they are currently. |
@Porges - Good point 👍 |
Reopening and marking as up-for-grabs. This isn't high on our priority list but it's a good feature to have. |
We are getting a bunch of these warnings as well. The code accumulated dozens of warnings such as importing a target file several times, even though we have TreatWarningsAsErrors=true. |
We are in the same situation. Use caseMisconfigured Platform across a Solution Having some dependency that require a specific platform (e.g. x64) but that when build from msbuild using the solution configuration matrix produce:
Since this is plugged in a CI/CD workflow, it would be nice to be able to block the release process in this case. |
We want the appveyor builds to fail if a PR introduces new warnings. However we don't want the dev to deal with this permanently as they are working towards a PR. Essentially we want gated checkins that also prevents users from introducing new warnings. Simply being able to do this through a commandline would be the easiest way. |
I'm working on this for MSBuild 15. DesignA new command-line argument All Warnings as ErrorsSpecifying just Example
Specifying Which Warnings Should Be ErrorsSpecifying a comma-delimited list of warning codes will treat just that set of warnings as errors. The value can include duplicates and only that set will be logged as errors and the build will fail. Example
This will also work within response files. Suppressing WarningsAlthough we don't recommend it, there are cases when it might be necessary to suppress warnings. To do this, you'll be able to specify a comma-delimited list of warning codes to suppress. You must specify a list of warnings to suppress as we will not be just suppressing everything. Example
Open Questions
Please send me any feedback on this design. |
This design would satisfy our needs. Replacing "can not" with "cannot" in the first open question would make it easier to understand. |
Does this mean we can't enable this in .csproj? That would suck ☹ |
@dotMorten The problem is that project properties are declared too late. MSBuild logs warnings during project evaluation which would mean they could not be turned into errors. For example: <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="true or true and true">
<MSBuildWarningsAsErrors>MSB4130</MSBuildWarningsAsErrors>
</PropertyGroup>
<Target Name="Build" />
</Project> Results in the MSB4130 warning:
The warning is logged before the It might be possible to add a new property to the You had original stated:
And this design should provide this capability. Does this seem reasonable? |
Specify just /WarnAsError to have all warnings logged as errors as well as have the build fail. Specify a comma delimited list of warning codes to have just that set of warnings treated as errors as well as have the build fail. Targets will still show as succeeded and the tasks will continue to execute but the overall build result will be a failure. Related to dotnet#68 and will close in my next change to add /NoWarn.
Specify just /WarnAsError to have all warnings logged as errors as well as have the build fail. Specify a comma delimited list of warning codes to have just that set of warnings treated as errors as well as have the build fail. Targets will still show as succeeded and the tasks will continue to execute but the overall build result will be a failure. Related to dotnet#68 and will close in my next change to add /NoWarn.
Specify just /WarnAsError to have all warnings logged as errors as well as have the build fail. Specify a comma delimited list of warning codes to have just that set of warnings treated as errors as well as have the build fail. Targets will still show as succeeded and the tasks will continue to execute but the overall build result will be a failure. Related to dotnet#68 and will close in my next change to add /NoWarn.
Specify just /WarnAsError to have all warnings logged as errors as well as have the build fail. Specify a comma delimited list of warning codes to have just that set of warnings treated as errors as well as have the build fail. Targets will still show as succeeded and the tasks will continue to execute but the overall build result will be a failure. Related to dotnet#68 and will close in my next change to add /NoWarn.
Specify just /WarnAsError to have all warnings logged as errors as well as have the build fail. Specify a comma delimited list of warning codes to have just that set of warnings treated as errors as well as have the build fail. Targets will still show as succeeded and the tasks will continue to execute but the overall build result will be a failure. Related to dotnet#68 and will close in my next change to add /NoWarn.
Specify just /WarnAsError to have all warnings logged as errors as well as have the build fail. Specify a list of warning codes to have just that set of warnings treated as errors as well as have the build fail. Targets will still show as succeeded and the tasks will continue to execute but the overall build result will be a failure. Related to dotnet#68 and will close in my next change to add /NoWarn. * Feature switch FEATURE_RESOURCEMANAGER_GETRESOURCESET * Support for command-line arguments having empty values
Warnings are logged as low importance messages instead. This way they can still be seen with more verbosity but are essentially suppressed. Closes dotnet#68
Specify just /WarnAsError to have all warnings logged as errors as well as have the build fail. Specify a list of warning codes to have just that set of warnings treated as errors as well as have the build fail. Targets will still show as succeeded and the tasks will continue to execute but the overall build result will be a failure. Related to dotnet#68 and will close in my next change to add /NoWarn. * Feature switch FEATURE_RESOURCEMANAGER_GETRESOURCESET * Support for command-line arguments having empty values
We used to recommend that all tasks return [edited to make sense] |
The logic will be if you specify /warnaserror than the overall build result will fail if any errors are logged. Individual targets can still show as "Success". So if I build pragmatically via If all of the tasks return |
@jeffkl - I am not sure I am convinced on the command line switch vs. MSBuild property argument. |
@iouri-s The main concern is that if you set a property to suppress a warning and there is ever a case where that warning wouldn't be treated as an error, it defeats the purpose of this functionality. My example above is not really a corner case in my opinion. Do you think an environment variable would good enough? I believe that the local build experience will still show warnings unless people manually specify to treat them as errors. But the I would love to come up with a way to have the warning list be an MSBuild property but I just don't see a way to ensure that what is specified will actually be treated as an error. |
Specify just /WarnAsError to have all warnings logged as errors as well as have the build fail. Specify a list of warning codes to have just that set of warnings treated as errors as well as have the build fail. Targets will still show as succeeded and the tasks will continue to execute but the overall build result will be a failure. Related to #68 and will close in my next change to add /NoWarn. * Feature switch FEATURE_RESOURCEMANAGER_GETRESOURCESET * Support for command-line arguments having empty values
Warnings are logged as low importance messages instead. This way they can still be seen with more verbosity but are essentially suppressed. Closes dotnet#68
Warnings are logged as low importance messages instead. This way they can still be seen with more verbosity but are essentially suppressed. Closes dotnet#68
You cannot suppress all warnings, if you specify empty `/warnasmessage` or `/nowarn`, you get an error message. Warnings are mutated into just a message. Ignore the first commit which is the implementation of /WarnAsError Closes #68 Closes #47 Closes #910 So this: ``` MyProject.proj(3,18): warning MSB4130: The condition "true or true and true" may have been evaluated incorrectly in an earlier version of MSBuild. Please verify that the order of the AND and OR clauses is written as intended. To avoid this warning, add parentheses to make the evaluation order explicit. ``` Becomes this in with Verbosity=Detailed ``` MyProject.proj(3,18): message MSB4130: The condition "true or true and true" may have been evaluated incorrectly in an earlier version of MSBuild. Please verify that the order of the AND and OR clauses is written as intended. To avoid this warning, add parentheses to make the evaluation order explicit. ``` Here is the help message for review: ``` /warnasmessage[:code[;code2]] List of warning codes to treats as low importance messages. Use a semicolon or a comma to separate multiple warning codes. (Short form: /nowarn[:c;[c2]]) Example: /warnasmessage:MSB3026 ```
@jeffkl Hey Jeff, have you talked to anyone inside Visual Studio to get an option inside VS to turn this on? |
I never noticed this was closed. Thanks @jeffkl! 👍 |
Any update on this? |
@memark the command-line arguments shipped in MSBuild 15.1 and the properties shipped in MSBuild 15.3 via #1928 |
.. which was getting overwritten by an older one, due to a bad merge! The older one is missing the commit a5a9fd5, required for linux builds. Thanks to @directhex for catching this.
@jeffkl this is a great improvement, thank you! This was closed quite a while ago. Since then, have you worked with the VS team to get this added as a VS option as @davkean mentioned? Until that exists, it's my understanding that there is simply no way to control this behavior for any Visual-Studio-Driven workflows. In our specific case, we would want to add a property to Of note, for native C/C++ projects, we have |
@solvingj
|
Thank you for that @rainersigwald . I was actually more specifically needing to solve this related issue of suppressing specific warnings, in my case I'm about to look at that link you provided to see if there's a mechanism for this as well. |
It looks like this has no effect, likely due to the limitation explained in the start of the PR. I guess the remaining questions is, how is it possible that there is no way for the user to append/alter or otherwise affect the |
@rainersigwald , if I understand this comment correctly, Visual Studio should support MSBuildWarningsAsErrors. It isn't working for me. Here is my Directory.Build.props.
I am using Visual Studio 2019. When I build my solution it doesn't fail the build or output the warnings as errors to the error pane. It just outputs them in the warning pane like before I set the MSBuildWarningsAsErrors setting. Also, I did this after deleting the .vs folder and clearing the bin and obj folders. On the other hand, Rider and MSBuild will fail and show the errors. What do you or anyone else recommend we do to get this fixed? p.s. I know I put the same warnings in both MSBuildWarningsAsErrors and WarningsAsErrors. I wasn't sure what the difference was, so I used both. |
@MattBussing I don't reproduce your problem. Can you file a new issue with more details (ideally a repro project) please?
Great news! As of #5774 you can just use In the past, * This may actually be the problem you're seeing; some of MSBuild's warnings are emitted before we can read this property and thus can't be changed by the property. But please let us know the specific problem you're seeing. |
@rainersigwald , thank you so much for the quick response! Thanks for your patience while I filed another issue. Here is the issue with a project that reproduces the error. #6473 So what you are saying for the second part is that |
Correct, in MSBuild 16.9 and higher. |
I would like an option to be able to treat all warnings as errors, when running from the command line.
The text was updated successfully, but these errors were encountered: