StyleCop : Setting Rule explained

We will try to understand how to write the XML content to suppress rules. The sample XML can be found in the older post here.

Lets try to understand the XML attributes & tag in below mentioned points:

  1. AnalyzerId : You have to mentioned the class name of the rule often found in warning or error of the StyleCop.
  2. Name : You need to mentioned the actual rule that you are trying to suppress. You can find the entire list of rules in here. (For some reason if you are unable to open the chm file. Right click the file => Properties => unblock the file)
  3. <BooleanProperty> : Make sure the Value under this tag is false.
  4. You can have multiple Rule tags under a Rules tag. Make sure all the rule comes under same class name.
  5. Similarly you have multiple Analyzer tags under a Analyzers tag.

StyleCop : Global Rule Suppression

We want to suppress rules of style cop for all the projects in the developer machine. As you can get few information from the documentation both on global rule setting and rule suppression. Below mentioned are 2 ways to merge them both:

Editing the Settings.StyleCop in notepad

  1. Go to the installation location of StyleCop (possible location: “C:\Program Files\StyleCop 4.7”)
  2. Right click Settings.StyleCop file open with notepad.
  3. Replace below XML Content as a child node of <Analyzer>
  4. <Analyzer
       <Rule Name="ElementsMustBeDocumented">
         <BooleanProperty Name="Enabled">
  5. The trick to read the above xml can be found here.
  6. Close and Save the file.

Editing the Settings.StyleCop using the default editor

  1. Go to the installation location of StyleCop (possible location: “C:\Program Files\StyleCop 4.7”)
  2. Double click on the file named Settings.StyleCop
  3. The Rule editor will be open (It will look like this)
  4. Simply un-check the rules you don’t want in your projects.
  5. Click Apply and Ok.

Both the solution will give you same result, you can use them as per your convenience.