FxCop不尊重我的排除

时间:2010-09-18 16:35:27

标签: c# msbuild fxcop msbuildcommunitytasks

我正在尝试将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工具生成的。有什么想法吗?

1 个答案:

答案 0 :(得分:8)

您是否将CODE_ANALYSIS符号添加到项目的条件编译符号中?