MSBuild C++ - command line - can pass defines?
Macros may be defined by passing the /D
option to the compiler. You can specify the /D
option from MSBuild using the AdditionalOptions
of ClCompile
:
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/DERROR_LOG_LEVEL=5 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
If you want to be able to pass the value for the macro via a call to msbuild.exe, you can easily do that too:
<ItemDefinitionGroup Condition="'$(ErrorLogLevel)' != ''">
<ClCompile>
<AdditionalOptions>/DERROR_LOG_LEVEL=$(ErrorLogLevel) %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
with msbuild.exe invoked as:
msbuild /p:ErrorLogLevel=5 MyProject.vcxproj