安装自定义StyleCop规则

时间:2016-02-19 13:07:42

标签: c# stylecop

在开始创建自定义StyleCop规则时,我已按照Visual StyleCop Github上的说明进行操作。

•我创建了一个班级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>

其他可能相关的事实:

  • 此库正在发布中,在Framework 3.5中构建。

  • 我已将此库的发布版本与StyleCop

  • 放在同一目录中
  • 我使用StyleCop.MSBuild(版本4.7.50)进行StyleCop集成,因此我将其复制到\packages\StyleCop.MSBuild.{version}\tools

  • 库中引用的StyleCop版本与我旁边复制的版本相同。 (我已经使用ILSpy检查了版本。)

  • 我使用的是Visual Studio 2015,但我没有使用分析器

我打开Settings.StyleCop文件时看不到规则,也没有看到任何与Visual Studio一起运行的迹象。

enter image description here

我错过了什么?

1 个答案:

答案 0 :(得分:1)

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>