Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

command line msbuild with multiple DefineConstants

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"
like image 881
George Mauer Avatar asked Jul 18 '14 16:07

George Mauer


2 Answers

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

like image 99
srinivas n Avatar answered Oct 30 '22 13:10

srinivas n


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"
like image 33
Mike Zboray Avatar answered Oct 30 '22 12:10

Mike Zboray