I'm using this idea to inject preprocessor definitions from a command line build script using a global named $(DefineConstants)
.
vcxproj file snippet:
<PropertyGroup Label="Globals">
<DefineConstants></DefineConstants>
</PropertyGroup>
...
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>$(DefineConstants);WIN32;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
My script launches msbuild
with the following (abridged) command line:
msbuild.exe Solution.sln /p:DefineConstants=FOO%3BBAR
where FOO%3BBAR
is dynamic and comes from any number of user-supplied values. (Using %3B
as a separator comes from this thread since using a raw ;
character results in an error.)
But the compiler (cl
) command line shows that the entire value of $(DefineConstants)
is getting placed into a single /D
switch instead of getting split into multiple.
ClCompile:
CL.exe ... /D "FOO;BAR" /D WIN32 /D _WINDOWS
It's as if the semicolons inside the variable aren't expanded. Is there any way to make it produce /D FOO /D BAR
?
Summary of things I've tried so far:
msbuild command line |
results in cl command line |
comment |
---|---|---|
/p:DefineConstants=FOO%3BBAR |
/D "FOO;BAR" |
wrong: not split into multiple /D |
/p:DefineConstants="FOO;BAR" |
/D "\"FOO" /D "BAR\"" |
wrong: split, but includes \" |
/p:DefineConstants=FOO;BAR |
n/a | error: property not valid |