From powershell
Set-Alias msbuild C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
and running from the same directory as my sln file
> msbuild /nologo /property:DefineConstants=FOO
works just fine. Let's say I need two build time constants though.
> msbuild /nologo /property:DefineConstants=FOO;BAR
Powershell interprets the semi-colon as an end-of-statement and runs with a single constant and then tries to run the command BAR
and errors. So not what I want.
How about?
> msbuild /nologo /property:DefineConstants="FOO;BAR"
MSBUILD : error MSB1006: Property is not valid.
Switch: BAR
This doesn't work either. Not sure what's going on here but it seems to be interpreting "FOO;BAR" as some sort of single thing - not two constants.
So. How do I actually pass in multiple constants?
Edit Upon further investigation, I'm running the following in cmd.exe
>C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe /nologo /property:DefineConstants=FOO;BAR
MSBUILD : error MSB1006: Property is not valid.
Switch: BAR
although this works
>C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe /nologo /property:DefineConstants="FOO;BAR"
We can use msbuild escape characters as msbuild /t:rebuild "/property:DefineConstants=PROD%3BCODE_ANALYSIS". Where %3B is to use ; in properties.
https://msdn.microsoft.com/en-us/library/bb383819.aspx
https://msdn.microsoft.com/en-us/library/ms228186.aspx
Two ideas:
Add quotes around the property flag and escape the double quotes
msbuild /nologo "/property:DefineConstants=`"FOO;BAR`""
Use the call operator &
(works in PS v4+)
& msbuild /nologo /property:DefineConstants="FOO;BAR"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With