简体   繁体   中英

MSBuild - Treat Warnings from editorconfig as Errors (enforce during build)

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM