Using StyleCop in Core Asp.net

According to this article for using StyleCop in Core Asp.net,

1) Add the following to the dependencies section of the project.json file:

"StyleCop.Analyzers": { "version": "1.0.0", "type": "build" } 

and build a project.

2) Create stylecop.json and add your configuration to it, this is my stylecop.json content:

 { "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", "settings": { "documentationRules": { "documentInterfaces": true, "documentInternalMembers": false } } } 

3) the following in the buildOptions node file in the project.json file:

  "additionalArguments": ["/additionalfile:path/to/stylecop.json" ] 

but I got some errors: what is the problem?

enter image description here

+5
source share
1 answer

Short answer

Those NullReferenceException errors occur when StyleCop cannot find your stylecop.json . Here's a link

Full working example

Directory structure

 bin obj Program.cs project.json project.lock.json stylecop.json StyleCop.ruleset 

Project.json

 { "version": "1.0.0-*", "buildOptions": { "debugType": "portable", "emitEntryPoint": true, "warningsAsErrors": true, "nowarn": [ "1591" ], "xmlDoc": true, "additionalArguments": [ "/ruleset:./StyleCop.ruleset", "/additionalfile:./stylecop.json" <----- This is probably the problem. ] }, "dependencies": { "StyleCop.Analyzers": { "type": "build", "version": "1.0.0" } }, "frameworks": { "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.1" } } } } } 

stylecop.json

 { "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", "settings": { "documentationRules": { "documentExposedElements": false, "documentInterfaces": false } } } 

StyleCop.ruleset

 <?xml version="1.0" encoding="utf-8"?> <RuleSet Name="New Rule Set" Description=" " ToolsVersion="14.0"> <Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers"> <Rule Id="SA0000" Action="Warning" /> <Rule Id="SA1005" Action="Warning" /> <Rule Id="SA1208" Action="Warning" /> <Rule Id="SA1028" Action="Warning" /> <Rule Id="SA1210" Action="Warning" /> </Rules> </RuleSet> 

Clone and run an example

 git clone git@github.com :bigfont/StackOverflow.git cd .\StackOverflow\AspNetCoreStyleCop\ dotnet restore dotnet build 
+2
source

Source: https://habr.com/ru/post/1262118/


All Articles