问题
I have been struggling with this for a while. I have searched and tried different things but it does not work, so I am posting this here.
I want to treat warnings as errors when building on TFS level and this option has not been working.
I have done it like suggested on other posts: I have tried: /p:TreatWarningsAsErrors=true and /p:TreatWarningsAsErrors="true"
Enabling TreatWarningsAsErrors
However, that as been unsuccessful as when building I have the following result: The warning is not treated as error on TFS build.
Warning About Unused int
The build is successful As the image below shows and there are no errors.
No errors in build
Can anyone help me with insight on this about how to do it?
Update: Obs: I do know the option to set TreatWarningAsErrors on the properties of the project when using VS2017 and that works, as warning are treated as errors there, but that does not work for TFS.
TreatWarningAsError on VS2017 project properties
Warning becomes error
I have enabled treat warnings as errors in VS2017, under project properties, for both Debug and Release.
Build on TFS
回答1:
I tested at my side, the argument /p:TreatWarningsAsErrors="true"
works for me:
Note that if you have enabled the Treat Warnings As Errors
in VS (set to ALL
or Specific Warnings
) for the project, then you don't need to add the argument /p:TreatWarningsAsErrors="true"
anymore.
So, you can try below things to narrow down the issue:
- Enable the option (Set to
All
), then check in changes, then build again. - Disable the option (set to
None
, just keep it as default), clean caches for your client server, then create a new build definition, add the argument/p:TreatWarningsAsErrors="true"
in build step. Queue a build to check if that works for you.
UPDATE:
As Kevin mentioned in below comment, the problem is that SonarQube
seems to be interfering somehow.... Just created a new build definition identical to the first one but without SonarQube Analysis and the warnings became errors in the build of the solution.
回答2:
We use a TFS Build Extension for that, Build Quality Checks. Setting the build to fail above a threshold of 0 will fail the build on any compiler warnings:
来源:https://stackoverflow.com/questions/46963089/treat-warnings-as-errors-on-tfs-level-vs2017