I build my solution using MSBUILD on command line like this:
msbuild %SOLUTION% /m /fl /flp:LogFile="%OUTPUTFILE%" /p:Configuration=%BUILDCONFIG% /p:RunCodeAnalysis=True
Having /p:RunCodeAnalysis=True
creats code analysis results for both native (PREfast) and managed (FxCop) code, but my problem is, that the analysis result files for native code are not placed into $(OutDir)
like it is the case for the manged code results. They are stored in the obj
folder of each assembly (=$(IntDir)
) instead.
I tracked down the path to the standard target file Microsoft.CodeAnalysis.Targets
, and then changed the line
<MergedOutputCodeAnalysisFile>$(IntDir)vc.nativecodeanalysis.all.xml</MergedOutputCodeAnalysisFile>
to
<MergedOutputCodeAnalysisFile>$(OutDir)$(TargetName).nativecodeanalysis.TEST.xml</MergedOutputCodeAnalysisFile>
and it worked, but I can't ask every developer to change this file on his/her system, so I need a way to set this inside the project files. I have already tried following methods, but had no success:
Add a property to each project file (on the root level):
<PropertyGroup> <OutputCodeAnalysisFile>$(OutDir)$(TargetName).NativeCodeAnalysis.TEST.xml</OutputCodeAnalysisFile> </PropertyGroup>
Calling MSBUILD with the desired property value:
msbuild %SOLUTION% /m /fl /flp:LogFile="%OUTPUTFILE%" /p:Configuration=%BUILDCONFIG% /p:RunCodeAnalysis=True /p:MergedOutputCodeAnalysisFile="$(OutDir)$(TargetName).nativecodeanalysis.TEST.xml"
Using target injection by adding this lines to the
vcxproj
file after<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>
Does anybody know, how to solve the problem without touching the standard code analysis target?