Reputation: 147
I set up an .editorconfig
file for my project and it works perfectly in my IDE and throws the right warnings. Examples: IDE0052 (unused variables) and IDE0055 (wrong formatting).
However, I would like to enforce the warnings from my .editorconfig
as errors during Build so that it fails. Is there any way to do this? Setting properties MSBuildTreatWarningsAsErrors
or TreatWarningsAsErrors
to true in the csproj hasn't done anything.
Thank you!
Upvotes: 11
Views: 9133
Reputation: 1654
I think you need two things to make this work.
Firstly, in your .csproj file set the following:
<PropertyGroup>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
Secondly, in your .editorconfig file use the following format to set the severity level when building
dotnet_diagnostic.IDE0052.severity = error
Without the first part, I was only able to get an error generated on the build but that wouldn't cause the build to fail (oddly enough).
This test was run using VS 2019 v16.8.4
Check out this resource for more information code-analysis-overview
Upvotes: 17