81

I'm using StyleCop. But there a couple of rules I want to ignore, for instance using this. in front of class members.

How do I turn off a StyleCop rule. I've looked but can't find how to do it.

3 Answers 3

82

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.

You can also put copies of the settings file into your projects to override the global settings.

If you're using Visual Studio integration and not just MSBuild integration, you should be able to get to the settings editor on a per-project basis by right clicking on your project and choosing StyleCop Settings or something like that.

9
  • Where's that settings file? Does that apply if you have resharper installed too?
    – War
    Sep 27, 2012 at 8:52
  • For version 4.7, it's C:\Program Files (x86)\StyleCop 4.7\Settings.StyleCop. The ReSharper integration will also look there (as well as looking at any overriding settings files in your project)
    – bdukes
    Sep 27, 2012 at 13:42
  • ah thanks :) ...annoying when i have over 100 projects and i need to turn off 1 rule for them all.
    – War
    Sep 28, 2012 at 8:39
  • 4
    @Wardy If you have all of then in the same solution, you can have the Settings.StyleCop file at the same directory as your .sln file.
    – J.A.I.L.
    May 21, 2013 at 11:19
  • 4
    @Harrison, have you tried using StyleCopSettingsEditor.exe on your Settings.StyleCop file, instead of editing it by hand? It's in C:\Program Files (x86)\StyleCop 4.7
    – bdukes
    Nov 11, 2013 at 15:23
11

Stylecop is configurable at Project level. Manage rules easily using graphical interface instead of editing settings file.(Some time in some versions mentioned as Stylecop settings)

You should see a search/Find Option once you select the settings option as in the below image.

Ex: If you want to remove a rule where // comments are not allowed and //// are allowed by stylecop, then search for stylecop rule id. In this case it is SA1005. You can see this in the warnings section when you run stylecop in your project. Find with key word SA1005 and you should see that in result section. Just uncheck.

enter image description here

You can manage rules as below

enter image description here

2
  • I think you can setup ONE csproj this way, then "move" the Settings.StyleCop file to a higher up folder (..\.. for example) and it will apply to everything at/under that folder. Dec 20, 2018 at 22:47
  • (repeat comment from another answer, but helpful to prevent extra work) ::: Extra tip. If you have a directory struture like \root\Pres\Pres.csproj, \root\Bal\Bal.csproj, \root\Dal\Dal.csproj and \root\Solutions\MySolution.sln, you can right click any of the projects.......create the rules......(\root\Bal\Settings.StyleCop for example) BUT you can manually move that file to \root\Settings.StyleCop..........and it will be "global" for \root\, aka, your entire solution. Dec 12, 2019 at 14:05
6

That specific rule is under Readability Rules - Member Access - SA1101: PrefixLocalCallsWithThis.

If you turn that off it should stop screaming at you... I had to do it. Stylecop has been giving me a headache.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.