Roslyn-analyzers: [Question] Easiest way to configure Microsoft.CodeAnalysis.FxCopAnalyzers to apply classical rulesets

Created on 23 Apr 2016  路  14Comments  路  Source: dotnet/roslyn-analyzers

For the classical static code analysis you could use predefined Microsoft rule sets like Managed Recommended Rules.

Is there an easy way to configure FxCopAnalyzers to only apply rules that are within a certain rule set? The workflow we are currently using is the following:

  • Disable all FxCopAnalyzers rules (there might be rules enabled by default which are not in the desired rule set)
  • Go through each rule, look if it exists in the desired rule set (for example in the Managed Recommended Rules ruleset) and enable it again if it does

This is somehow tedious, so I wonder if there is a better way to do this?

Area-Infrastructure Bug

Most helpful comment

Do we have rulset support in version 2.0?

All 14 comments

This is one of the primary tasks that we need to do prior to releasing 1.2.0 bits of this package. Currently, there is no non-trivial way to do this.

FYI @srivatsn

Do we have rulset support in version 2.0?

@jinujoseph There have been multiple requests for this now. I will spend some time on this tomorrow to see if I can come up with a quick solution so our cibuild also generates:

  1. A ruleset which disables all rules from the analyzer package
  2. Classical FxCop rulesets which include the above ruleset, and then turn on the relevant rules.
  3. Package the above rulesets in our analyzer NuGet packages.

I think we need this for a good compat story anyways.

+1

+1

I have a PR out to package classical and auxiliary rulesets along with each analyzer package: https://github.com/dotnet/roslyn-analyzers/pull/1718

Kindly, take a look at the description and screenshots in the PR to confirm this satisfies everyone's ask.

@Dresel @axelheer @alextolp @curia-damiano

Also tagging @gewarren. We probably want to document https://github.com/dotnet/roslyn-analyzers/pull/1718#issue-194133287 and https://github.com/dotnet/roslyn-analyzers/pull/1718#issuecomment-396423976 on docs.microsoft.com, so customers who wants to migrate from legacy FxCop to FxCop analyzers without altering their existing rule configuration can use the new rulesets that we package with the analyzer packages.

@mavasani will do, thanks.

Looks good. Thanks 馃憤

Can you please describe how those rulesets can be used in a project? I tried adding <CodeAnalysisRuleSet>..\rulesets\legacy\MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> with different paths and ended with just copying the ruleset folder to my project.

@zivillian Relative paths will not work as the ruleset location is relative to the NuGet package root. You either need to explicitly define/reference NuGet package root and package version in your absolute path OR copy over the required ruleset files to your project directory.

Was this page helpful?
0 / 5 - 0 ratings