安装自定义 StyleCop 规则

Installing Custom StyleCop Rule

在开始创建自定义 StyleCop 规则时,我遵循了 Visual StyleCop Github 上的说明。

• 我创建了 class、MyStyleCopRules.cs:

[SourceAnalyzer(typeof(CsParser))]
public class MyStyleCopRules : SourceAnalyzer
{
    public override void AnalyzeDocument(CodeDocument document)
    {
       ...

• 添加了 XML 文档,构建操作设置为 EmbeddedResource,名为 MyStyleCopRules.xml:

<?xml version="1.0" encoding="utf-8" ?>
<SourceAnalyzer Name="My StyleCop Rules">
    <Rules>
      <Rule Name="Fully Qualified Using Statements" CheckId="IS0001">
        <Context>Using statements must be fully qualifed.</Context>
        <Description>Fires when using statements are not fully qualifed.</Description>
      </Rule>
    </Rules>
</SourceAnalyzer>

其他可能相关的事实:


我打开 Settings.StyleCop 文件时没有看到规则,也没有看到任何迹象表明它们 运行 和 Visual Studio


我错过了什么?

Fully Qualified Using Statements 中不能有空格。

即:

<?xml version="1.0" encoding="utf-8" ?>
<SourceAnalyzer Name="My StyleCop Rules">
    <Rules>
      <Rule Name="FullyQualifiedUsingStatements" CheckId="IS0001">
        <Context>Using statements must be fully qualifed.</Context>
        <Description>Fires when using statements are not fully qualifed.</Description>
      </Rule>
    </Rules>
</SourceAnalyzer>