我在命令行上使用 MSBUILD 构建我的解决方案,如下所示:
msbuild %SOLUTION% /m /fl /flp:LogFile="%OUTPUTFILE%" /p:Configuration=%BUILDCONFIG% /p:RunCodeAnalysis=True
/p:RunCodeAnalysis=True
为本地(PREfast)和托管(FxCop)代码创建代码分析结果,但我的问题是,本地代码的分析结果文件没有像$(OutDir)
托管代码结果那样放入。它们存储在obj
每个程序集 (= $(IntDir)
) 的文件夹中。
我跟踪到标准目标文件的路径Microsoft.CodeAnalysis.Targets
,然后更改了行
<MergedOutputCodeAnalysisFile>$(IntDir)vc.nativecodeanalysis.all.xml</MergedOutputCodeAnalysisFile>
至
<MergedOutputCodeAnalysisFile>$(OutDir)$(TargetName).nativecodeanalysis.TEST.xml</MergedOutputCodeAnalysisFile>
它有效,但我不能要求每个开发人员在他/她的系统上更改这个文件,所以我需要一种在项目文件中设置它的方法。我已经尝试了以下方法,但没有成功:
为每个项目文件添加一个属性(在根级别):
<PropertyGroup> <OutputCodeAnalysisFile>$(OutDir)$(TargetName).NativeCodeAnalysis.TEST.xml</OutputCodeAnalysisFile> </PropertyGroup>
使用所需的属性值调用 MSBUILD:
msbuild %SOLUTION% /m /fl /flp:LogFile="%OUTPUTFILE%" /p:Configuration=%BUILDCONFIG% /p:RunCodeAnalysis=True /p:MergedOutputCodeAnalysisFile="$(OutDir)$(TargetName).nativecodeanalysis.TEST.xml"
通过将此行添加到
vcxproj
文件中来使用目标注入<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
:<PropertyGroup> <RunMergeNativeCodeAnalysisDependsOn> $(RunMergeNativeCodeAnalysisDependsOn); CustomOutputNativeCodeAnalysisFile </RunMergeNativeCodeAnalysisDependsOn> </PropertyGroup> <Target Name="CustomOutputNativeCodeAnalysisFile"> <PropertyGroup> <OutputCodeAnalysisFile>$(OutDir)$(TargetName).NativeCodeAnalysis.TEST.xml</OutputCodeAnalysisFile> </PropertyGroup> </Target>
有谁知道,如何在不触及标准代码分析目标的情况下解决问题?