How do I build a solution in MSBuild (command line only) with PGI/PGO without adding new build configuration to projects? I've tried to add command line parameter /property:WholeProgramOptimization=PGInstrument which looks OK, it creates PGD files but does not create PGC after I ran the application. Obviously I'm missing something in MSBuild command line.
I spent two days scratching my head on this problem and I finally found how to do it:
First you need to build the instrumented version of your program:
msbuild.exe
/t:Rebuild "Letter:\path\YourProject.vcxproj"
/p:Configuration=Release
/p:Platform=x64
/p:WholeProgramOptimization=PGInstrument
Note that On my machine, MSBuild can be found here:
C:\Program Files (x86)\MSBuild\12.0\Bin\msbuild.exe
. The order of the parameters are really important. If your project were placed after the /p options, it could overwrite them.
A pgd file should have been created in your output directory. You will need its path later.
Then you need to instrument the program:
Letter:\path\OutPutDir\YourProject.exe
In this step obviously you need to add parameters to feed your program with the data it needs. If your program complains about not having access to pgort120.dll you can add a line like this one to your script: set PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64
Finally you can build the optimized version of your program:
msbuild.exe
/t:LibLinkOnly "Letter:\path\YourProject.vcxproj"
/p:Configuration=Release
/p:Platform=x64
/p:WholeProgramOptimization=PGOptimize
/p:LinkTimeCodeGeneration=PGOptimization
/p:ProfileGuidedDatabase="Letter:\path\OutPutDir\YourProject.pgd"
Here you need to use the address of the pgd file of the first step. Note that the target is LibLinkOnly because there is no need to recompile everything.
Hope this helps others.