我正在使用所有相同的规则ID构建多个规则集文件,但是包含的MS规则集的级别会上升,并且某些规则的Action的严重性会增加。我遇到的问题是VS2010告诉我加载FXCop_VS2010_HIGLevel2.ruleset文件时出错,而FXCop_VS2010_HIGLevel1.ruleset加载正常。它们看起来基本相同:
FXCop_VS2010_HIGLevel1.ruleset
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="HIG VS2010 Code Analysis Rules Level 1" Description="These rules expand on the basic design guideline rules to maximize the usability and maintainability issues that are reported. Extra emphasis is placed on naming guidelines. Consider including this rule set if your project includes library code or if you want to enforce the highest standards for writing maintainable code." ToolsVersion="10.0">
<Include Path="BasicCorrectnessRules.ruleset" Action="Default" />
<Include Path="SecurityRules.ruleset" Action="Default" />
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1000" Action="None" />
<Rule Id="CA1001" Action="None" />
...
<Rule Id="CA2239" Action="Warning" />
<Rule Id="CA2240" Action="None" />
<Rule Id="CA2242" Action="None" />
<Rule Id="CA2243" Action="None" />
</Rules>
</RuleSet>
FXCop_VS2010_HIGLevel2.ruleset
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="HIG VS2010 Code Analysis Rules Level 2" Description="These rules expand on the basic design guideline rules to maximize the usability and maintainability issues that are reported. Extra emphasis is placed on naming guidelines. Consider including this rule set if your project includes library code or if you want to enforce the highest standards for writing maintainable code." ToolsVersion="10.0">
<Include Path="BasicCorrectnessRules.ruleset" Action="Default" />
<Include Path="BasicDesignGuidelineRules.ruleset" Action="Default" />
<Include Path="SecurityRules.ruleset" Action="Default" />
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1000" Action="Warning" />
<Rule Id="CA1001" Action="None" />
...
<Rule Id="CA2239" Action="Warning" />
<Rule Id="CA2240" Action="None" />
<Rule Id="CA2242" Action="None" />
<Rule Id="CA2243" Action="None" />
</Rules>
</RuleSet>
你可以看到它们基本相同。级别2添加BasicDesignGuidelineRules.ruleset并更改某些规则的操作(即CA1000从级别1的“无”变为级别2的“警告”)。
当我将Level 2规则集文件放入Static Analysis Tools \ Rule Sets文件夹时,这是我从VS2010获得的错误:
为什么会发生这种情况?我逐行浏览了Level 2 XML,并且运行了一个与Level 1相比较的文件。唯一的区别就是我的预期。我使用Notepad ++在适当的位置显示非打印字符,而不是CRLF。我很难过。
答案 0 :(得分:0)
当您在评论中提供支持时,您说在将操作从CriticalWarning
更改为Warning
,CriticalError
更改为Error
后问题得到了解决。
此处解释了此行为:http://msdn.microsoft.com/en-us/library/dd380626.aspx
您必须误认为自定义规则XML文件中的MessageLevel property
操作。在此属性中,您可以设置以下值: