2016-02-19 278 views
1

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

•我创建了一个类,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(50年4月7日版)的集成了StyleCop,所以我将其复制到\packages\StyleCop.MSBuild.{version}\tools

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

  • 我使用Visual Studio 2015年,但我不使用分析仪


我不明白规则,当我打开Settings.StyleCop文件,我也没有看到他们使用Visual Studio运行的任何迹象。

enter image description here


有什么我错过了?

回答

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>