gpt4 book ai didi

asp.net-core - 在 Asp.net Core 中使用 StyleCop

转载 作者:行者123 更新时间:2023-12-02 14:15:14 27 4
gpt4 key购买 nike

根据这个this article在 Asp.net Core 中使用 StyleCop,

1)将以下内容添加到project.json文件的依赖项部分:

 "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" ]

但是我遇到了一些错误:问题是什么?

enter image description here

最佳答案

简短回答

当 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

项目.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.规则集

<?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

关于asp.net-core - 在 Asp.net Core 中使用 StyleCop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41407071/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com