【问题标题】:Msbuild property is not considered while passing as commandline parameter through powershell通过 powershell 作为命令行参数传递时不考虑 Msbuild 属性
【发布时间】:2011-12-26 14:21:10
【问题描述】:

我正在尝试使用 Powershell 通过命令行参数 ($args[0]) 传递属性,如下所示,但没有考虑。

if ( Test-path -path $args[0]) {
            &"$MsbuildBinPath\Msbuild.exe" $MSBuildFile  /t:BuildAll "/p:AllComponents=$args[0]"  $Logger $ErrorLogger
            if ($LastExitCode -ne 0) {
                    Write-Host "It failed, send a mail"
            }
    }

如果我像下面这样传递属性,则正在考虑中。

"/p:AllComponents=List.txt" 

为什么直接应用命令行参数时不考虑它?

我可以将命令行值存储在某个变量中并传递,但是有没有其他机制可以直接传递它?

【问题讨论】:

    标签: powershell msbuild powershell-2.0 msbuild-4.0


    【解决方案1】:

    $args[0] 没有在字符串中展开,您需要将其括在子表达式符号中:

    ... "/p:AllComponents=$($args[0])"
    

    要避免这种语法,请将参数分配给变量并将变量嵌入字符串中:

    $argsZero= $args[0]
    ... "/p:AllComponents=$argsZero"
    

    有关更多信息,请在控制台中输入以下内容:

    Get-Help about_Quoting_Rules
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-22
      相关资源
      最近更新 更多