StyleCop Analyzers can be used with the dotnet tooling, including ASP.NET Core.
Edit the project file and add a package reference to StyleCop.Analyzers. Make sure to set PrivateAssets so the reference is not included when transitive dependencies are calculated across project references:
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004" PrivateAssets="All" />
</ItemGroup>
If the project is restored and built right now this will already run the analyzers. A few extra steps are needed if they should be configured.
Update the project file as follows to apply settings and custom rules:
<PropertyGroup>
...
<CodeAnalysisRuleSet>stylecop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>
Analyzers for XML documentation can only run if the XML documentation comment processing is enabled. See SA0001 for more information.
Update the project file to include the following:
<PropertyGroup>
...
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
Legacy projects use project.json to configure analyzers and other build options. Start by adding the following to
the dependencies
section of project.json:
"StyleCop.Analyzers": {
"version": "1.0.2",
"type": "build"
}
The rule set and configuration file can be configured by adding the following to the buildOptions
section:
"additionalArguments": [
"/ruleset:path/to/ruleset.ruleset",
"/additionalfile:path/to/stylecop.json"
],
"xmlDoc": "true"