Skip to content

Latest commit

 

History

History
80 lines (52 loc) · 2.87 KB

HowToConfigureRulesetFile.md

File metadata and controls

80 lines (52 loc) · 2.87 KB

How to: Configure Ruleset File

New csproj format (.NET Core, .NET Standard)

1) Add New Rule Set File to Your Solution

  • Go to Solution Explorer - Solution - Context Menu - Add - New Item - Code Analysis Rule Set

2) Modify Rule Set File Manually

  • Open ruleset file in text editor.
  • Change value of attribute 'Name' (ruleset is represented in the IDE by its name).

Edit Rule Set File

3) Attach Rule Set to Project(s)

  • Open csproj file in text editor or go to Solution Explorer - Project - Context Menu - Edit ProjectName.csproj
  • Add following PropertyGroup (or add element to the existing PropertyGroup):
<PropertyGroup>
  <CodeAnalysisRuleSet>RELATIVE_OR_ABSOLUTE_PATH_TO_RULESET_FILE</CodeAnalysisRuleSet>
</PropertyGroup>

Old csproj format (.NET Framework)

1) Create Your Own Rule Set File

  • Skip this step if you already have one.
  • Go to Solution Explorer - Solution - Project - References - Analyzers - Open Active Rule Set.

Open Active Rule Set

  • Modify ruleset.
  • Save ruleset (this will create a new file ProjectName.ruleset in your project folder.
  • Move ruleset file to a solution root folder (or any other location).

Rule Set Editor

2) Modify Rule Set File Manually

  • Open ruleset file in text editor.
  • Change value of attribute 'Name' (ruleset is represented in the IDE by its name).

Edit Rule Set File

3) Attach Rule Set to Project(s)

  • Go to Main Menu - Analysis - Configure Code Analysis - For Solution

Configure Code Analysis for Solution

  • Change ruleset for each project.
  • Change configuration and repeat previous step (optional).

Code Analysis Settings

Directory.Build.props File

It may be convenient to to specify ruleset in Directory.Build.props file. This file is typically located in a root folder of a solution.

<Project>
  <PropertyGroup>
    <CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)my.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
</Project>

See Also