FxCop,从程序集中排除规则(但将其用于其他程序集)
我想从 CoreTest 程序集中排除 CA1822:MarkMembersAsStatic,因为 NUnit 测试方法无法转换为静态方法,因为如果我这样做,NUnit 也不会执行它们。在其他集会中,我希望遵守这条规则,因为我发现它很有价值。
如果可能的话,我不喜欢向每个测试方法添加 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>
关于如何以最方便的方式完成此操作有什么想法吗?
I would like to exclude CA1822:MarkMembersAsStatic from the CoreTest assembly as the NUnit test methods cannot be converted to static methods as NUnit won´t execute them if I do. In the other assemblies I would like to have this rule as I have found it valuable.
If it is possible I do not like to add a SuppressMessage to each test methods, as I have a lot of them and it just clutters up the file.
This is the FxCop rule XML-file:
<?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>
Any ideas on how this can be done in the most convenient way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无法在单次 FxCop 运行中使用单独的规则集。为了处理 CA1822 测试方法问题,我通常创建两个单独的 FxCop 项目:一个包含用于正常组件的 CA1822,另一个不包含用于测试组件的 CA1822。
如果您使用集成到 Visual Studio 的某些“开发人员”团队版本中的代码分析功能,则可以对每个程序集应用不同的规则集。这是受支持的,因为该工具最终会为每个程序集单独运行 fxcopcmd.exe,而不是因为它使用一些更复杂的配置来支持单次运行中的多个规则集。
There's no way to use separate rule sets within a single FxCop run. For dealing with the CA1822 test method issue, I usually create two separate FxCop projects: one that includes CA1822 for normal assemblies, and one that excludes CA1822 for test assemblies.
If you're using the code analysis feature integrated into some of the "developer" team edition of Visual Studio, you can apply a different rule set to each assembly. This is supported because the tool ends up running fxcopcmd.exe seperately for each assembly, not because it uses some more complex configuration to support multiple rule sets within a single run.