禁用代码分析输出MSBuild

时间:2014-05-26 12:13:43

标签: msbuild code-analysis fxcop

我正在使用构建定义构建项目。执行此操作时,还会执行代码分析。代码分析输出各种文件,包括:

ConsoleApplication2.exe.CodeAnalysisLog.xml
ConsoleApplication2.exe.lastcodeanalysissucceeded

有没有办法在我的构建定义中禁用此输出,例如通过参数或类似的东西?

3 个答案:

答案 0 :(得分:5)

可以使用CodeAnalysisGenerateSuccessFile选项禁用成功标记文件的生成。 e.g

<CodeAnalysisGenerateSuccessFile>false</CodeAnalysisGenerateSuccessFile>

没有阻止生成日志文件的选项,但您可以通过CodeAnalysisLogFile选项将其移动到其他位置。例如,要将其放在项目根文件夹中,可以使用以下命令:

<CodeAnalysisLogFile>CodeAnalysisLog.xml</CodeAnalysisLogFile>

答案 1 :(得分:1)

我找到了lastcodeanalysissucceeded文件的选项。

通过提供输入参数:/p:CodeAnalysisGenerateSuccessFile=false,不会生成文件。

我还没有找到一个禁用日志文件输出的输入参数。如下所述的模式设置并没有涵盖它。

<xs:element name="CodeAnalysisInputAssembly" type="msb:StringPropertyType" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisInputAssembly" _locComment="" -->Path to the assembly to be analyzed by Code Analysis. The default is '$(OutDir)$(TargetName)$(TargetExt)'.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisLogFile" type="msb:StringPropertyType" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisLogFile" _locComment="" -->Path to the output file for the Code Analysis report. The default is '$(CodeAnalysisInputAssembly).CodeAnalysisLog.xml'.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisLogFileXsl" type="msb:StringPropertyType" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisLogFileXsl" _locComment="" -->Path to the XSL style sheet to reference in the Code Analysis output report. This report is specified in $(CodeAnalysisLogFile). The default is an empty string ('').</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisModuleSuppressionsFile" type="msb:StringPropertyType" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisModuleSuppressionsFile" _locComment="" -->Name of the file, without the path, where Code Analysis project-level suppressions are stored. The default is 'GlobalSuppressions$(DefaultLanguageSourceExtension)'.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisOverrideRuleVisibilities" type="msb:boolean" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisOverrideRuleVisibilities" _locComment="" -->Indicates whether to run all overridable Code Analysis rules against all targets. This will cause specific rules, such as those within the Design and Naming categories, to run against both public and internal APIs, instead of only public APIs. The default is false.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisOutputToConsole" type="msb:boolean" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisOutputToConsole" _locComment="" -->Indicates whether to output Code Analysis warnings and errors to the console. The default is false.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisVerbose" type="msb:boolean" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisVerbose" _locComment="" -->Indicates whether to output verbose Code Analysis diagnostic info to the console. The default is false.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisPath" type="msb:StringPropertyType" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisPath" _locComment="" -->Path to the Code Analysis installation folder. The default is '$(VSINSTALLDIR)\Team Tools\Static Analysis Tools\FxCop'.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisPlatformPath" type="msb:StringPropertyType" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisPlatformPath" _locComment="" -->Path to the .NET Framework folder that contains platform assemblies, such as mscorlib.dll and System.dll. The default is an empty string ('').</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisProject" type="msb:StringPropertyType"  substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisProject" _locComment="" -->Path to the Code Analysis project (*.fxcop) to load. The default is an empty string ('').</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisQuiet" type="msb:boolean" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisQuiet" _locComment="" -->Indicates whether to suppress all Code Analysis console output other than errors and warnings. This applies when $(CodeAnalysisOutputToConsole) is true. The default is false.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisRuleAssemblies" type="msb:StringPropertyType" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisRuleAssemblies" _locComment="" -->Semicolon-separated list of paths either to Code Analysis rule assemblies or to folders that contain Code Analysis rule assemblies. The paths are in the form '[+|-][!][file|folder]', where '+' enables all rules in rule assembly, '-' disables all rules in rule assembly, and '!' causes all rules in rule assembly to be treated as errors. For example '+D:\Projects\Rules\NamingRules.dll;+!D:\Projects\Rules\SecurityRules.dll'. The default is '$(CodeAnalysisPath)\Rules'.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisRuleDirectories" type="msb:StringPropertyType" substitutionGroup="msb:Property">
     <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisRuleDirectories" _locComment="" -->Semicolon-separated list of directories in which to search for rules when resolving a rule set. The default is '$(CodeAnalysisPath)\Rules' unless the CodeAnalysisIgnoreBuiltInRules property is set to true.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisRules" type="msb:StringPropertyType" substitutionGroup="msb:Property">
     <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisRules" _locComment="" -->Semicolon-separated list of Code Analysis rules. The rules are in the form '[+|-][!]Category#CheckId', where '+' enables the rule, '-' disables the rule, and '!' causes the rule to be treated as an error. For example, '-Microsoft.Naming#CA1700;+!Microsoft.Naming#CA1701'. The default is an empty string ('') which enables all rules.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisRuleSet" type="msb:StringPropertyType" substitutionGroup="msb:Property">
     <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisRuleSet" _locComment="" -->A .ruleset file which contains a list of rules to run during analysis. The string can be a full path, a path relative to the project file, or a file name. If a file name is specified, the CodeAnalysisRuleSetDirectories property will be searched to find the file. The default is an empty string ('').</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisRuleSetDirectories" type="msb:StringPropertyType" substitutionGroup="msb:Property">
     <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisRuleSetDirectories" _locComment="" -->Semicolon-separated list of directories in which to search for rule sets. The default is '$(VSINSTALLDIR)\Team Tools\Static Analysis Tools\Rule Sets' unless the CodeAnalysisIgnoreBuiltInRuleSets property is set to true.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisSaveMessagesToReport" type="msb:StringPropertyType" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisSaveMessagesToReport" _locComment="" -->Comma-separated list of the type ('Active', 'Excluded', or 'Absent') of warnings and errors to save to the output report file. The default is 'Active'.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisSearchGlobalAssemblyCache" type="msb:boolean" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisSearchGlobalAssemblyCache" _locComment="" -->Indicates whether Code Analysis should search the Global Assembly Cache (GAC) for missing references that are encountered during analysis. The default is true.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisSummary" type="msb:boolean" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisSummary" _locComment="" -->Indicates whether to output a Code Analysis summary to the console after analysis. The default is false.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisTimeout" type="msb:StringPropertyType" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisTimeout" _locComment="" -->The time, in seconds, that Code Analysis should wait for analysis of a single item to complete before it aborts analysis. Specify 0 to cause Code Analysis to wait indefinitely. The default is 120.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisTreatWarningsAsErrors" type="msb:boolean" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisTreatWarningsAsErrors" _locComment="" -->Indicates whether to treat all Code Analysis warnings as errors. The default is false.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisUpdateProject" type="msb:boolean" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisUpdateProject" _locComment="" -->Indicates whether to update the Code Analysis project (*.fxcop) specified in $(CodeAnalysisProject). This applies when there are changes during analysis. The default is false.</xs:documentation>
    </xs:annotation>
</xs:element>
<xs:element name="CodeAnalysisUseTypeNameInSuppression" type="msb:boolean" substitutionGroup="msb:Property">
    <xs:annotation>
        <xs:documentation><!-- _locID_text="CodeAnalysisUseTypeNameInSuppression" _locComment="" -->Indicates whether to include the name of the rule when Code Analysis emits a suppression. The default is true.</xs:documentation>
    </xs:annotation>

答案 2 :(得分:0)

我无法获得Matthijs和Nicole Calinoiu提供的两个答案,但是在进一步调查之后,我偶然发现了this question在StackOverflow上。

简而言之,不建议您禁用这些文件,以免普遍输出。根据 seva titov 在上面链接的问题中的回答:

首先,即使没有任何更改,删除.lastcodeanalysissucceededd也会导致代码分析重新运行。其次,删除.CodeAnalysisLog.xml将几乎不可能调查分析错误和警告的详细信息。因此,您最好关闭该项目的代码分析。

因此,最好仅将这两个文件移动到中间文件位置。该位置是所有*.obj文件,*.log文件和其他元文件所在的位置。为此,请右键单击您的项目,然后单击“ 卸载项目”。

unload project

然后,右键单击该项目,然后单击Edit p͟r͟o͟j͟e͟c͟t͟.vcxproj。在图片中,我单击Edit Test1.vcxproj,因为我的演示项目称为Test1

edit vcxproj file

然后,在项目标签</Project>的末尾,您将看到一堆<Import ...>语句。在这些导入语句之后放置the question中描述的属性组:

<PropertyGroup>
    <CodeAnalysisLogFile>
        $(IntermediateOutputPath)$(TargetFileName).CodeAnalysisLog.xml
    </CodeAnalysisLogFile>
    <CodeAnalysisSucceededFile>
        $(IntermediateOutputPath)$(TargetFileName).lastcodeanalysissucceeded
    </CodeAnalysisSucceededFile>
</PropertyGroup>

例如,它看起来应该像这样:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <!-- 
        ...
        A lot of other stuff not shown
        ...
    -->

    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    <ImportGroup Label="ExtensionTargets">
    </ImportGroup>

    <!-- The following will move the code analysis output files and put them in the intermediate folder -->
    <PropertyGroup>
        <CodeAnalysisLogFile>
            $(IntermediateOutputPath)$(TargetFileName).CodeAnalysisLog.xml
        </CodeAnalysisLogFile>
        <CodeAnalysisSucceededFile>
            $(IntermediateOutputPath)$(TargetFileName).lastcodeanalysissucceeded
        </CodeAnalysisSucceededFile>
    </PropertyGroup>
</Project>