根据这篇
this article在Asp.net Core中使用StyleCop,
1)将以下内容添加到project.json文件的dependencies部分:
"StyleCop.Analyzers": { "version": "1.0.0","type": "build" }
并构建项目.
2)创建stylecop.json并在其上添加配置,这是我的stylecop.json内容:
{ "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json","settings": { "documentationRules": { "documentInterfaces": true,"documentInternalMembers": false } } }
3)project.json文件中的buildOptions节点下面的以下内容:
"additionalArguments": ["/additionalfile:path/to/stylecop.json" ]
但是我遇到了一些错误:问题是什么?
解决方法
简答
当StyleCop找不到您的stylecop.json时,会发生NullReferenceException错误.这是related GitHub issue.
要修复它(假设你的stylecop.json在你的项目的根目录中),改变它的路径:
"additionalArguments": [ "/additionalfile:./stylecop.json" ]
完整的工作示例
目录结构
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>
克隆并运行示例
git clone git@github.com:bigfont/StackOverflow.git cd .\StackOverflow\AspNetCoreStyleCop\ dotnet restore dotnet build
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。