Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: temporarily disable StyleCop

Can you disable styleCop in VS?

Scenario:

  1. Press "Disable StyleCop" button
  2. Run/debug some test code
  3. The button automatically, enable StyleCop again. Therefore you have to actively disable it again it you want to run without StyleCop.
like image 357
Chris G. Avatar asked Jun 18 '13 08:06

Chris G.


People also ask

How do I enable StyleCop?

By default, JetBrains Rider does not read settings from StyleCop files (RuleSet and Settings. StyleCop). To start taking these settings into account, select the Enable StyleCop support checkbox on the Editor | Code Style page of JetBrains Rider settings Ctrl+Alt+S and choose which StyleCop file format should be used.

How do I ignore a StyleCop warning?

Starting with StyleCop 4.3. 2, it is possible to suppress the reporting of rule violations by adding suppression attributes within the source code. The syntax for these suppressions is similar to that for Visual Studio Code Analysis, or FxCop.


2 Answers

You can disbale StyleCop for the entire solution by placing a Settings.StyleCop in the root of your solution folder, with the following contents:

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

You'll need to restart Visual Studio after doing so.

like image 81
Dimitri Troncquo Avatar answered Sep 18 '22 19:09

Dimitri Troncquo


I've setup a separate build configuration that doesn't run code analysis.

I now have the following configurations in VS:

  • Release
  • Debug
  • Debug (No code analysis)

You have to manually choose which configuration you want to build (i.e. step 3 in your list would be a manual step)

In the build targets file I've included code along these lines:

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
    <RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
    <RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug (No code analysis)' ">
    <RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>

<PropertyGroup>
    <DefineConstants Condition="('$(RunCodeAnalysis)'=='true') and '$(Language)'=='C#' ">CODE_ANALYSIS;$(DefineConstants)</DefineConstants>
</PropertyGroup>
like image 32
Montgomery 'monty' Jones Avatar answered Sep 17 '22 19:09

Montgomery 'monty' Jones