29

I've installed Stylecop via NuGet. I wish to disable some rules, and I know this can be done via a configuration file from what I've read. However, I can't find the file anywhere, and there seems to be little documentation describing where to create the file.

How do I go about making the file?

Edit: As this question still seems to be getting attention a couple of years later, I recommend using Roslyn Analyzer based StyleCop now.

This has a few advantages:

  1. It's actually maintained and active.
  2. Takes advantage of Roslyn, and can perform some changes for you.
  3. It's a NuGet package so is installed as part of your projects, meaning you no longer need to install the seemingly unmaintained StyleCop Visual Studio extension (that's if you can even find the right place to download it from in the first place!). This way you can enforce code style/conventions much easier in for example OSS.
  4. Automatically creates the .ruleset file for you, and as a result of using Roslyn Analyzers you get IDE support for enabling/disabling rules.
user9993
  • 5,833
  • 11
  • 56
  • 117

3 Answers3

33

If you installed Stylecop via NuGet (the StyleCop.MSBuild package), then you will not have the folder detailed in the other answers.

You will find the file in your project folder here:
packages\StyleCop.MSBuild.{version}\tools\Settings.StyleCop

You should copy this file to the root of your project.

If you would rather not manually edit the file, there is also a nice gui tool called StyleCopSettingsEditor in the tools folder, which you can just drag your settings file onto.

Hywel Rees
  • 884
  • 1
  • 15
  • 22
12

If you copy the Settings.StyleCop file to the root of the solution, then it will be inherited by all projects. This means it can be kept in Source Control and accessed by any Continuous Integration server you are using.

If you reference and alter the file in C:\Program Files (x86)\StyleCop {{version}}\Settings.StyleCop this needs to be kept inline on each developer's PC. where as copying it to the root of the solution

Kevin
  • 16,549
  • 8
  • 60
  • 74
NikolaiDante
  • 18,469
  • 14
  • 77
  • 117
3

The file Settings.StyleCop should be located in your install directory, on my machine it's here:

C:\Program Files (x86)\StyleCop 4.7\Settings.StyleCop

You can edit the rule settings by opening this file with StyleCopSettingsEditor.exe, located in the same directory (double-clicking the settings file will do the trick).

Rufus L
  • 36,127
  • 5
  • 30
  • 43
  • I haven't installed StyleCop, the only version seems to be some odd version from 2012, so I installed it through NuGet directly into my project – user9993 Mar 22 '15 at 04:06
  • Maybe I'm, too stupid. But isn't StyleCop, especially ReSharper+StyleCop somewhat confusing? I'm glad that someone continues development at https://github.com/StyleCop/StyleCop – anhoppe Sep 17 '15 at 10:04