Disable stylecop analysis for specific projects within solution

levelnis picture levelnis · Mar 18, 2013 · Viewed 14.1k times · Source

Is there a way to easily stop StyleCop warnings from being displayed within specific projects in a solution. Or, more pointedly, a way to select which projects StyleCop analysis should be performed on by Visual Studio?

We have a solution with 9 projects in it. There are only 2 projects that I actually want to see StyleCop warnings for, so I've created StyleCop.Settings files within those project root directories. This means that, for the rest of the projects, the default rule set is applied and I get a screen full of warnings every time I open a class.

The only way I can think to remove these warnings is to add another StyleCop.Settings file a folder level above with all the rules switched off and set merge options on the specific Settings files I am interested in to not merge with this parent file. This just feels wrong though. Is there a cleaner option or is this my only one?

UPDATE: I'm specifically looking for a way to stop the warnings from appearing within Visual Studio. I've added a Settings.StyleCop file to the solution folder and disabled all the rules. I run StyleCop analysis across one of my test projects and there are no errors reported. However, opening a test class reveals a raft of StyleCop warnings, which I want to suppress. Could this be the StyleCop for ReSharper plugin? I have a code cleanup profile created and have disabled certain rules within there but that doesn't appear to make any difference within my test classes.

Answer

Alexander Tsvetkov picture Alexander Tsvetkov · Mar 18, 2013

Please have a look at File Lists configuration - they allow to disable rules by default per project:

Enabled Or Disabled By Default

In addition, a new setting allows you to determine whether rules should be enabled or disabled by default. This can be set either at the project level or at the SourceFileList level. For example, here’s how you would set up a project with all rules disabled by default, and only two rules explicitly enabled:

<StyleCopSettings Version="4.3">
    <GlobalSettings>
        <BooleanProperty Name="RulesEnabledByDefault">False</BooleanProperty>
    </GlobalSettings>