问题
I've added the SonarLint C# Roslyn analyzer to a project (via the SonarAnalyzer for C# NuGet package) in Visual Studio. Is it possible to configure how the analyzer rules operate?
For example, the CodeComplexity analyser appears to have a Threshold property to which I'd like to set a different value.
I've found a couple of references to a SonarLint.xml file, but creating such a file and locating it at the solution level doesn't seem to have had any effect.
Here's the content of the SonarLint.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<AnalysisInput>
<Rules>
<Rule>
<Key>S3776</Key>
<Parameters>
<Parameter>
<Key>threshold</Key>
<Value>30</Value>
</Parameter>
</Parameters>
</Rule>
</Rules>
<Files>
</Files>
</AnalysisInput>
回答1:
Include the SonarLint.xml file in the project and set the Build Action
file property to AdditionalFiles
.
Diving in to the SonarLint source code led me to this class, which makes use of the AnalyzerOptions class. This then led me to the documentation in the Roslyn repository about Additional Files.
来源:https://stackoverflow.com/questions/42989826/configure-sonarlint-analyzers-properties