我正在尝试传递一个简单的变量传递,
无参数
msbuild MySolution.sln /p:Configuration=Debug /p:Platform="Any CPU"
尝试1个
$buildOptions = '/p:Configuration=Debug /p:Platform="Any CPU"'
msbuild MySolution.sln + $buildOptions
->导致MSB1008
尝试2
$command = "msbuild MySolution.sln" + $buildOptions
Invoke-expression $command
->导致MSB1009
我在这篇文章中尝试了这个解决方案,但我认为这是一个不同的错误。
尝试其中一种:
msbuild MySolution.sln $buildOptions
Start-Process msbuild -ArgumentList MySolution.sln,$buildOptions -NoNewWindow
顺便说一句,PowerShell v3中有一个新功能,仅针对这种情况,--%之后的任何内容都将按原样处理,因此您的命令看起来像:
msbuild MySolution.sln --% /p:Configuration=Debug /p:Platform="Any CPU"
有关详细信息,请参阅此帖子:http://rkeithhill.wordpress.com/2012/01/02/powershell-v3-ctp2-provides-better-argument-passing-to-exes/
您需要在MySolution.sln
和参数列表之间放置一个空格。正如你所拥有的,命令行会导致
msbuild MySolution.sln/p:Configuration=Debug /p:Platform="Any CPU"
MSBuild会将"MySolution.sln/p:Configuration=Debug"视为项目/解决方案文件的名称,从而生成MSB10009: Project file does not exist.
。
您需要确保生成的命令行是这样的(注意MySolution.sln
:后面的空格
msbuild MySolution.sln /p:Configuration=Debug /p:Platform="Any CPU"
有很多方法可以确保使用Powershell语法,其中之一是:
$buildOptions = '/p:Configuration=Debug /p:Platform="Any CPU"'
$command = "msbuild MySolution.sln " + $buildOptions # note the space before the closing quote.
Invoke-Expression $command