Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable stylecop analysis for specific projects within solution

Tags:

c#

stylecop

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.

like image 264
levelnis Avatar asked Mar 18 '13 09:03

levelnis


People also ask

How do I turn off StyleCop analyzers?

right-click on a project in Project Explorer. select "StyleCop Settings" on the "Rules" tab of the dialog that opens, uncheck the "C#" root of the Enabled rules tree.

How do I turn off StyleCop rules?

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.

Is StyleCop still used?

StyleCop used to be a Visual Studio plugin and a NuGet package. You can still use this in Visual Studio 2019, but the current recommended way to use StyleCop is to use the Roslyn-based analyzers.


1 Answers

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>
like image 172
Alexander Tsvetkov Avatar answered Oct 07 '22 04:10

Alexander Tsvetkov