We are using StyleCop Analyzers in a C# project. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers) The problem is how to set all action to "Error" instead of "Warning" about both rules code analysis(CAXXXX) and style analysis(SAXXXX). Obviously I could list all rules like:
<Rule Id="CAXXXX" Action="Error" />
<Rule Id="SAXXXX" Action="Error" />
But that is inconvenient. Is there any other way to set it ?
The project used stylecop and set propertyGroup:
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
to set action as error. But that does not work in the new tool, stylecop analyzers.
In your StyleCop install, there's a Settings. StyleCop file. You can edit this to turn off rules globally. Drag that file onto the Settings Editor executable in that file to edit it.
StyleCop used to be a Visual Studio plugin and a NuGet package. You can still use this in Visual Studio 2019, but the current recommended way to use StyleCop is to use the Roslyn-based analyzers.
A quicker way to do this is:
On Analyzers, click Active Ruleset:
Giving something akin to:
Select them all:
Then click on any "Warning" and select "Error":
Then they are all set to "Error":
To set all code analysis rules to have an Error action by default, the following can be added to a property group in the .csproj file:
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
This worked for both Microsoft.CodeAnalysis.FxCopAnalyzers and StyleCop.Analyzers packages added to a .NET Core 2.1 project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With