- Go to Solution Explorer - Solution - Context Menu - Add - New Item - Code Analysis Rule Set
- Open ruleset file in text editor.
- Change value of attribute 'Name' (ruleset is represented in the IDE by its name).
- 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 existingPropertyGroup
):
<PropertyGroup>
<CodeAnalysisRuleSet>RELATIVE_OR_ABSOLUTE_PATH_TO_RULESET_FILE</CodeAnalysisRuleSet>
</PropertyGroup>
- Skip this step if you already have one.
- Go to Solution Explorer - Solution - Project - References - Analyzers - 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).
- Open ruleset file in text editor.
- Change value of attribute 'Name' (ruleset is represented in the IDE by its name).
- Go to Main Menu - Analysis - Configure Code Analysis - For Solution
- Change ruleset for each project.
- Change configuration and repeat previous step (optional).
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>