Skip to content

Windows Programming Quick Reference

Audio

MSDN:

SAL, Error Code, and Other Info

MSDN:

MSBuild.exe Command-line

Basics

Example location under Visual Studio

c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe 

Build a Visual Studio project/solution with specific configuration and platform:

msbuild.exe my_sample.sln -p:Configuration=Release -p:Platform=x64

Clean and build the projection/solution:

msbuild.exe my_sample.sln -t:Clean;Build

Specify some preprocessors from command-line

As of 2019/11, there seems no straight-forward solution for this task. One reasonable work-around is to create a user-defined variable in vcxproj file to pass the preprocessors from command-line to the compile command.

  • Step 1: Modify vcxproj to add a user-specified variable to the <AdditionalOptions> element under <ClCompile>
  • Step 2: Set the user-specified variable in the CMD environment where msbuild will be invoked.

Assuming the user-specified variable is named "ExternalCompilerOptions", step 1 will add/modify the <ClCompile> element in the vcxproj file as follows:

<ClCompile>  
    <AdditionalOptions>$(ExternalCompilerOptions)</AdditionalOptions>  
</ClCompile>  

Now, to compile the project with a preprocessor FOO defined, and another preprocessor BAR defined as 1, the user just set the ExternalCompilerOptions accordingly before calling msbuild

set ExternalCompilerOptions=/DFOO /DBAR=1  
msbuild my_sample.sln