2010-09-14 25 views
2

我想排除CA1822:從CoreTest組件MarkMembersAsStatic作爲NUnit測試方法不能被轉換爲靜態方法作爲NUnit的不會致使執行它們如果我做。在其他議會中,我希望有這個規則,因爲我發現它很有價值。的FxCop,排除來自一個組件的規則(但將其用於其他組件)

如果有可能,我不喜歡一個SuppressMessage添加到每個測試方法,因爲我有很多人,它只是雜波該文件。

這是FxCop的規則XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<FxCopProject Version="1.35" Name="Foo, Release"> 
<ProjectOptions> 
    <SharedProject>True</SharedProject> 
    <Stylesheet Apply="False">http://www.gotdotnet.com/team/fxcop//xsl/1.35/FxCopReport.xsl</Stylesheet> 
    <SaveMessages> 
    <Project Status="None" 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" /> 
    <VersionAware>False</VersionAware> 
    <OverrideRuleVisibilities>False</OverrideRuleVisibilities> 
    <CustomDictionaries SearchFxCopDir="True" SearchUserProfile="True" SearchProjectDir="True" /> 
    <SearchGlobalAssemblyCache>False</SearchGlobalAssemblyCache> 
    <DeadlockDetectionTimeout>120</DeadlockDetectionTimeout> 
</ProjectOptions> 
<Targets> 
    <AssemblyReferenceDirectories> 
    <Directory>$(ProjectDir)/Library/EPiServer CMS/5.2.375.7/</Directory> 
    <Directory>$(ProjectDir)/Foo.Plugin/bin/Release/</Directory> 
    </AssemblyReferenceDirectories> 
    <Target Name="$(ProjectDir)/Foo.Core/bin/Release/Foo.Core.dll" Analyze="True" AnalyzeAllChildren="True" /> 
    <Target Name="$(ProjectDir)/Foo.CoreTest/bin/Release/Foo.CoreTest.dll" Analyze="True" AnalyzeAllChildren="True" /> 
    <Target Name="$(ProjectDir)/Foo.Example/bin/Foo.Example.dll" Analyze="True" AnalyzeAllChildren="True" /> 
    <Target Name="$(ProjectDir)/Foo.Web.WebForms/bin/Release/Foo.Web.WebForms.dll" Analyze="True" AnalyzeAllChildren="True" /> 
</Targets> 
<Rules> 
    <RuleFiles> 
    <RuleFile Name="$(FxCopDir)\Rules\DesignRules.dll" Enabled="True" AllRulesEnabled="True" /> 
    <RuleFile Name="$(FxCopDir)\Rules\GlobalizationRules.dll" Enabled="True" AllRulesEnabled="False"> 
    <Rule Name="AvoidDuplicateAccelerators" Enabled="True" /> 
    <Rule Name="DoNotHardcodeLocaleSpecificStrings" Enabled="True" /> 
    <Rule Name="SetLocaleForDataTypes" Enabled="True" /> 
    <Rule Name="SpecifyCultureInfo" Enabled="True" /> 
    <Rule Name="SpecifyIFormatProvider" Enabled="True" /> 
    <Rule Name="SpecifyMessageBoxOptions" Enabled="True" /> 
    </RuleFile> 
    <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\UsageRules.dll" Enabled="True" AllRulesEnabled="True" /> 
    </RuleFiles> 
    <Groups /> 
    <Settings /> 
</Rules> 
<FxCopReport Version="1.35" /> 
</FxCopProject> 

上如何能以最便捷的方式完成的任何想法?

回答

2

有沒有辦法在單個的FxCop運行中使用不同的規則集。爲了處理CA1822測試方法問題,我通常創建兩個獨立的FxCop項目:一個包含CA1822用於常規裝配,另一個不包括用於測試裝配的CA1822。

如果您正在使用集成到一些Visual Studio中的「開發者」團隊版的代碼分析功能,您可以將不同的規則設置爲每個組件。這是受支持的,因爲該工具最終會爲每個程序集單獨運行fxcopcmd.exe,而不是因爲它在一次運行中使用了一些更復雜的配置來支持多個規則集。

相關問題