Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
禁用代码分析输出MSBuild_Msbuild_Code Analysis_Fxcop - Fatal编程技术网

禁用代码分析输出MSBuild

禁用代码分析输出MSBuild,msbuild,code-analysis,fxcop,Msbuild,Code Analysis,Fxcop,我正在使用构建定义构建项目。执行此操作时,还将执行代码分析。代码分析输出各种文件,包括: ConsoleApplication2.exe.CodeAnalysisLog.xml ConsoleApplication2.exe.lastcodeanalysissucceeded 是否有任何方法可以禁用生成定义中的此输出,例如通过参数或类似的方式?我找到了lastcodeanalysissuccessed文件的一个选项 通过提供输入参数:/p:CodeAnalysisGenerateSuccess

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

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

是否有任何方法可以禁用生成定义中的此输出,例如通过参数或类似的方式?

我找到了
lastcodeanalysissuccessed
文件的一个选项

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

我还没有找到一个禁用日志文件输出的输入参数。下面所述的schemasettings没有涵盖它

<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>

要通过代码分析进行分析的程序集的路径。默认值为“$(OutDir)$(TargetName)$(targetText)”。
代码分析报告的输出文件的路径。默认值为“$(CodeAnalysisInputAssembly).CodeAnalysisLog.xml”。
代码分析输出报告中要引用的XSL样式表的路径。此报告在$(CodeAnalysisLogFile)中指定。默认值为空字符串(“”)。
存储代码分析项目级抑制的文件名,不带路径。默认值为“GlobalSuppressions$(DefaultLanguageSourceExtension)”。
指示是否针对所有目标运行所有可重写的代码分析规则。这将导致特定规则(如设计和命名类别中的规则)同时针对公共和内部API运行,而不是仅针对公共API。默认值为false。
指示是否将代码分析警告和错误输出到控制台。默认值为false。
指示是否将详细代码分析诊断信息输出到控制台。默认值为false。
代码分析安装文件夹的路径。默认值为“$(VSINSTALLDIR)\Team Tools\Static Analysis Tools\FxCop”。
包含平台程序集(如mscorlib.dll和System.dll)的.NET Framework文件夹的路径。默认值为空字符串(“”)。
要加载的代码分析项目(*.fxcop)的路径。默认值为空字符串(“”)。
指示是否抑制除错误和警告之外的所有代码分析控制台输出。当$(CodeAnalysisOutputOconsole)为true时,此选项适用。默认值为false。
指向代码分析规则程序集或包含代码分析规则程序集的文件夹的路径列表(以分号分隔)。路径的格式为“[+|-][!][file | folder]”,其中“+”启用规则程序集中的所有规则“-”禁用规则程序集中的所有规则,以及“!”使规则程序集中的所有规则都被视为错误。例如“+D:\Projects\Rules\NamingRules.dll;+!”!D:\Projects\Rules\SecurityRules.dll'。默认值为“$(CodeAnalysisPath)\Rules”。
以分号分隔的目录列表,解析规则集时在其中搜索规则。除非CodeAnalysisIgnoreBuiltInRules属性设置为true,否则默认值为“$(CodeAnalysisPath)\Rules”。
以分号分隔的代码分析规则列表。规则的格式为“[+|-][!]Category#CheckId”,其中“+”启用规则“-”禁用规则,以及“!”导致规则被视为错误。例如,'-Microsoft.Naming#CA1700;+!微软。命名#CA1701'。默认值为空字符串(“”),用于启用所有规则。
一个.ruleset文件,其中包含分析期间要运行的规则列表。字符串可以是完整路径、相对于项目文件的路径或文件名。如果指定了文件名,将搜索CodeAnalysisRuleSetDirectory属性以查找该文件。默认值为空字符串(“”)。
要在其中搜索规则集的目录的分号分隔列表。除非CodeAnalysisIgnoreBuiltInRuleSets属性设置为true,否则默认值为“$(VSINSTALLDIR)\Team Tools\Static Analysis Tools\Rule Sets”。
要保存到输出报告文件的警告和错误类型(“活动”、“排除”或“不存在”)的逗号分隔列表。默认值为“活动”。
指示代码分析是否应在全局程序集缓存(GAC)中搜索分析期间遇到的缺少的引用。默认值为true。
指示分析后是否将代码分析摘要输出到控制台。默认值为false。
代码分析在中止分析之前应等待单个项的分析完成的时间(以秒为单位)。指定0以使代码分析无限期等待。默认值为120。
指示是否将所有代码分析警告视为错误。默认值为false。
指示是否更新$(CodeAnalysisProject)中指定的代码分析项目(*.fxcop)。这适用于分析过程中发生变化的情况。默认值为false。
指示在代码分析发出抑制时是否包括规则的名称。默认值为true。

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


我对Matthijs和Nicole Calinoiu提供的两个答案不满意,但在进一步调查后,我偶然发现了StackOverflow

简而言之,通常不建议禁用这些文件的输出。根据seva titov对上述问题的回答:

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

因此,最好将这两个文件移动到
<CodeAnalysisGenerateSuccessFile>false</CodeAnalysisGenerateSuccessFile>
<CodeAnalysisLogFile>CodeAnalysisLog.xml</CodeAnalysisLogFile>
<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>