Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Powershell Msbuild with parameter fails

I am trying to pass a simple variable passing,

No parameter

msbuild MySolution.sln /p:Configuration=Debug /p:Platform="Any CPU"

Try 1

$buildOptions = '/p:Configuration=Debug /p:Platform="Any CPU"'
msbuild MySolution.sln + $buildOptions

-> cause MSB1008

Try 2

$command = "msbuild MySolution.sln" + $buildOptions
Invoke-expression $command

-> cause MSB1009

I tried the solution on this post but I think it is a different error.

like image 613
Nap Avatar asked Mar 08 '12 09:03

Nap


2 Answers

Try one of these:

msbuild MySolution.sln $buildOptions

Start-Process msbuild -ArgumentList MySolution.sln,$buildOptions -NoNewWindow

By the way, there's a new feature in PowerShell v3 just for this kind of situations, anything after --% is treated as is, so you're command will look like:

msbuild MySolution.sln --% /p:Configuration=Debug /p:Platform="Any CPU"

See this post for more information: http://rkeithhill.wordpress.com/2012/01/02/powershell-v3-ctp2-provides-better-argument-passing-to-exes/

like image 155
Shay Levy Avatar answered Nov 16 '22 03:11

Shay Levy


You need to put a space somewhere between MySolution.sln and the list of parameters. As you have it, the command line results in

   msbuild MySolution.sln/p:Configuration=Debug /p:Platform="Any CPU"

And MSBuild will consider "MySolution.sln/p:Configuration=Debug" to be name of the project/solution file, thus resulting in MSB10009: Project file does not exist..

You need to make sure that the resulting command line is something like this (note the space after MySolution.sln:

   msbuild MySolution.sln /p:Configuration=Debug /p:Platform="Any CPU"     

There are plenty of ways to assure that using Powershell syntax, one of them is:

   $buildOptions = '/p:Configuration=Debug /p:Platform="Any CPU"'
   $command = "msbuild MySolution.sln " + $buildOptions # note the space before the closing quote.

   Invoke-Expression $command
like image 26
Christian.K Avatar answered Nov 16 '22 04:11

Christian.K