Skip to content

Instantly share code, notes, and snippets.

@edgamat
Last active September 27, 2018 20:16
Show Gist options
  • Save edgamat/f5262e6d01a901b314344341cd232b10 to your computer and use it in GitHub Desktop.
Save edgamat/f5262e6d01a901b314344341cd232b10 to your computer and use it in GitHub Desktop.
Instructions for adding StyleCop to a .NET Core project

How to use StyleCop in .NET Core

Step 1: Add the StyleCop.Analyzers (nuget) package:

> dotnet add package StyleCop.Analyzers

Step 2: Add an empty file to the project called StyleCop.ruleset.

Step 3: Paste the following into StyleCop.ruleset and save the changes:

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="StyleCop Rules" Description="Code analysis rules" ToolsVersion="14.0">
  <Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
  </Rules>
</RuleSet>

Step 4: Add the following to the CSPROJ file:

  <PropertyGroup>
    <CodeAnalysisRuleSet>StyleCop.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>

Step 5: Build the project

> dotnet build

To Suppress a rule, add the following to the 'Rules' node in the ruleset:

<Rule Id="SA1101" Action="None" />

Example:

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="StyleCop Rules" Description="Code analysis rules" ToolsVersion="14.0">
  <Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
    <Rule Id="SA1101" Action="None" />
  </Rules>
</RuleSet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment