我正在尝试将 FxCop 直接合并到我的构建中。我正在使用 MSBuild 社区任务。我有一个这样的目标文件:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<FxCopToolPath Condition="'$(FxCopToolPath)' == ''">$(MetaSharpLibPath)\FxCop</FxCopToolPath>
<FxCopCustomDictionary Condition="'$(FxCopCustomDictionary)' == ''">$(FxCopTooLPath)\CustomDictionary.xml</FxCopCustomDictionary>
<MSBuildCommunityTasksLib>..\MSBuild.Community.Tasks\MSBuild.Community.Tasks.dll</MSBuildCommunityTasksLib>
</PropertyGroup>
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.FxCop" />
<Target Name="AfterBuild" >
<ItemGroup>
<FxCopRuleAssemblies Include="DesignRules.dll" />
<FxCopRuleAssemblies Include="GlobalizationRules.dll" />
<FxCopRuleAssemblies Include="InteroperabilityRules.dll" />
<FxCopRuleAssemblies Include="MobilityRules.dll" />
<FxCopRuleAssemblies Include="NamingRules.dll" />
<FxCopRuleAssemblies Include="PerformanceRules.dll" />
<FxCopRuleAssemblies Include="PortabilityRules.dll" />
<FxCopRuleAssemblies Include="SecurityRules.dll" />
<FxCopRuleAssemblies Include="SecurityTransparencyRules.dll" />
<FxCopRuleAssemblies Include="UsageRules.dll" />
<FxCopTargetAssembly Include="@(MainAssembly)" />
</ItemGroup>
<FxCop
ToolPath="$(FxCopToolPath)"
CustomDictionary="$(FxCopCustomDictionary)"
RuleLibraries="@(FxCopRuleAssemblies)"
TargetAssemblies="@(FxCopTargetAssembly)"
DependencyDirectories="@(ReferencePath)"
FailOnError="True"
ConsoleXslFileName="$(FxCopToolPath)\Xml\VSConsoleOutput.xsl"
DirectOutputToConsole="true" />
</Target>
</Project>
它工作得很好,除了当我添加 [SuppressMessage] 警告时,它们仍然出现在我的输出中。我创建了一个 .fxcop 项目文件并包含了输出程序集,并尝试以这种方式运行它,但发生了同样的事情。似乎 FxCop 不尊重我的压制,有什么想法吗?
这是一个不起作用的抑制示例 (GlobalSuppressions.cs):
[module: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "MetaSharp.Transformation.Lang")]
这是由 fxcop 工具生成的。有任何想法吗?
最佳答案
您是否将 CODE_ANALYSIS 符号添加到项目的条件编译符号中?
关于c# - FxCop 不尊重我的排除,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3742499/