通过添加 StyleCop.json 自定义 StyleCop

Customize StyleCop by adding StyleCop.json

我想自定义StyleCop规则,例如默认StyleCop需要在命名空间内添加所有using指令:

在我的项目中,我禁用了这个规则...现在我想修改这个规则(或添加一个新规则)这需要:

所有 using 指令都应该在命名空间之外定义

我看到了 this document,这说明可以通过添加 StyleCop.json:

来完成此自定义

The easiest way to add the file is to open a file that violates rule SA1633. This is the rule that requires a file header (e.g., a copyright notice). Press “CTRL + .” and you’ll see an option to add the file:

然后这个可以加到StyleCop.json:

"orderingRules": {
    "usingDirectivesPlacement": "outsideNamespace"
}

"CTRL + ."没有给我打开任何快捷操作,我不清楚how/where我应该在我的项目中添加StyleCop.Json

问题是我安装了 StyleCop 使用 StyleCop Installer

This document is expecting that StyleCop is installed using StyleCop.Analyzers Nuget 包。

我不确定在使用 StyleCop Installer 安装时如何自定义 StyleCop,但根据 Wikipedia,从 VS 2015 开始,StyleCop.Analyzers 是最佳选择。