Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild C++ - command line - can pass defines?

Is there a way to convert something like this:

#define ERROR_LOG_LEVEL 5

Into something that msbuild via command line will pass to its projects?

msbuild.exe {???}ERROR_LOG_LEVEL=5 target

I've read the responses to similar questions, and it looks like the answer is no, just want to double-check in case some genius has found a workaround.

like image 225
Yimin Rong Avatar asked Jan 15 '13 16:01

Yimin Rong


People also ask

How use MSBuild command line?

Use MSBuild at a command prompt To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.

What is MSBuild command line?

Builds the targets in the project file that you specify. If you don't specify a project file, MSBuild searches the current working directory for a file name extension that ends in proj and uses that file. You can also specify a Visual Studio solution file for this argument.

Can MSBuild build C++?

This walkthrough demonstrates how to use MSBuild in a command prompt to build a Visual Studio C++ project. You'll learn how to create an XML-based . vcxproj project file for a Visual C++ console application. After building the project, you'll learn how to customize the build process.

What compiler does MSBuild use?

By default, MSBuild will attempt to only run the TypeScript compiler when the project's source files have been updated since the last compilation.


1 Answers

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
like image 78
James McNellis Avatar answered Sep 23 '22 12:09

James McNellis