Вопрос

This question: Custom threshold for CA1502 discusses how to set up custom thresholds for code metrics rules in code analysis.

I have the same problem, but think that the old question is out of date.

To repeat:

In particular, we would like our Build to fail when a method has a code complexity of more than 20. Unfortunately, rule CA1502 has a threshold of 25:

The rule reports a violation when the cyclomatic complexity is more than 25.

Can we somehow change this?

The accepted answer is to edit an .fxcop file to include the rules. In visual studio 2013 ultimate we have integrated Code Analysis and Code metrics; but we don't appear to have .fxcop rules - I think this used to be when fxcop was a separate extension.

Is there any way to edit the thresholds in the .ruleset files produced by visual studio? Or have I missed how and where to get .fxcop files in the more recent versions?

Это было полезно?

Решение

The post you cited is actually pretty recent. The use of .fxcop files is still the only way to configure the rules. (If you're not fond of this limitation, you might want to vote at http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2406555-allow-code-analysis-rules-to-be-configured-via-ru.)

You can use the FxCop 10.0 UI to create a "seed" .fxcop file, but you will need to edit it by hand to add the settings. To integrate with Visual Studio, you can use the CodeAnalysisProject MSBuild property to specify the relative path to the .fxcop file.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top