在Visual Studio 2013中实现自定义CA1502规则以进行代码分析

时间:2015-03-07 16:36:23

标签: c# code-analysis static-code-analysis

我希望Visual Studio 2013的静态分析工具能够为CA1502(圈复杂度)发出警告,以获得低于所提供的默认分数(15而不是默认值25)的分数。以下Stack Overflow帖子讨论了如何使用FxCop 10.0创建默认的FxCop设置文件,然后需要通过调整项目和规则集文件将其集成到当前的静态代码分析工具(v 12.0)中:

custom threshold for CA1502 in visual studio 2013 ultimate

Custom threshold for CA1502

但是,除了调整FxCop设置文件所需的XML之外,没有关于将该设置文件实现到代码分析工具中的步骤的详细信息。例如,我查看项目文件,并且没有位置/设置列出项目文件中的所有规则库文件并禁用规则,因此可以通过规则集文件启用规则。我尝试了许多组合而没有成功。任何人都可以提供有关如何实施自定义设置的指导吗?

这是我的FxCop设置文件供参考:

<?xml version="1.0" encoding="utf-8"?>
<FxCopProject Version="10.0" Name="Test Project"> 
 <ProjectOptions>
  <SharedProject>True</SharedProject>
  <Stylesheet Apply="False">$(FxCopDir)\Xml\FxCopReport.xsl</Stylesheet>
  <SaveMessages>
   <Project Status="Active, Excluded" NewOnly="False" />
   <Report Status="Active" NewOnly="False" />
  </SaveMessages>
  <ProjectFile Compress="True" DefaultTargetCheck="True" DefaultRuleCheck="True" SaveByRuleGroup="" Deterministic="True" />
  <EnableMultithreadedLoad>True</EnableMultithreadedLoad>
  <EnableMultithreadedAnalysis>True</EnableMultithreadedAnalysis>
  <SourceLookup>True</SourceLookup>
  <AnalysisExceptionsThreshold>10</AnalysisExceptionsThreshold>
  <RuleExceptionsThreshold>1</RuleExceptionsThreshold>
  <Spelling Locale="en-US" />
  <OverrideRuleVisibilities>False</OverrideRuleVisibilities>
  <CustomDictionaries SearchFxCopDir="True" SearchUserProfile="True" SearchProjectDir="True" />
  <SearchGlobalAssemblyCache>False</SearchGlobalAssemblyCache>
  <DeadlockDetectionTimeout>120</DeadlockDetectionTimeout>
  <IgnoreGeneratedCode>False</IgnoreGeneratedCode>
 </ProjectOptions>
 <Targets />
 <Rules>
  <RuleFiles>
   <RuleFile Name="$(FxCopDir)\Rules\DesignRules.dll" Enabled="True" AllRulesEnabled="True" />
   <RuleFile Name="$(FxCopDir)\Rules\GlobalizationRules.dll" Enabled="True" AllRulesEnabled="True" />
   <RuleFile Name="$(FxCopDir)\Rules\InteroperabilityRules.dll" Enabled="True" AllRulesEnabled="True" />
   <RuleFile Name="$(FxCopDir)\Rules\MobilityRules.dll" Enabled="True" AllRulesEnabled="True" />
   <RuleFile Name="$(FxCopDir)\Rules\NamingRules.dll" Enabled="True" AllRulesEnabled="True" />
   <RuleFile Name="$(FxCopDir)\Rules\PerformanceRules.dll" Enabled="True" AllRulesEnabled="True" />
   <RuleFile Name="$(FxCopDir)\Rules\PortabilityRules.dll" Enabled="True" AllRulesEnabled="True" />
   <RuleFile Name="$(FxCopDir)\Rules\SecurityRules.dll" Enabled="True" AllRulesEnabled="True" />
   <RuleFile Name="$(FxCopDir)\Rules\SecurityTransparencyRules.dll" Enabled="True" AllRulesEnabled="True" />
   <RuleFile Name="$(FxCopDir)\Rules\UsageRules.dll" Enabled="True" AllRulesEnabled="True" />
  </RuleFiles>
  <Groups />
  <Settings>
    <Rule TypeName="AvoidExcessiveComplexity">
    <Entry Name="Warning Threshold">15</Entry>
    <Entry Name="Information Threshold">15</Entry>
    <Entry Name="Critical Warning Threshold">15</Entry>
    <Entry Name="Critical Error Threshold">15</Entry>
    <Entry Name="Error Threshold">15</Entry>
    <Entry Name="Recommended Threshold">"15""</Entry>
    </Rule>
  </Settings>
 </Rules>
 <FxCopReport Version="10.0" />
</FxCopProject>

0 个答案:

没有答案