【问题标题】:Simple Powershell Msbuild with parameter fails带参数的简单 Powershell Msbuild 失败
【发布时间】:2012-03-25 19:26:41
【问题描述】:

我正在尝试传递一个简单的变量传递,

无参数

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

我在this 帖子上尝试了解决方案,但我认为这是一个不同的错误。

【问题讨论】:

    标签: powershell msbuild


    【解决方案1】:

    尝试以下方法之一:

    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/

    【讨论】:

      【解决方案2】:

      您需要在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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-18
        • 2010-11-03
        • 1970-01-01
        • 2021-10-12
        • 1970-01-01
        • 2017-10-17
        • 2011-08-15
        • 1970-01-01
        相关资源
        最近更新 更多