Simple Powershell Msbuild with parameter fails

时光毁灭记忆、已成空白 提交于 2019-12-22 05:24:14

问题


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.


回答1:


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/




回答2:


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


来源:https://stackoverflow.com/questions/9615528/simple-powershell-msbuild-with-parameter-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!