【问题标题】:How to pass properties to chocolatey version of psake如何将属性传递给巧克力版的 psake
【发布时间】:2013-08-13 12:44:53
【问题描述】:

我已经使用 Chocolatey 安装了 psake。这允许您从 powershell 或 windows 命令行使用 psake 命令运行 psake。

但是,当我尝试使用以下命令将属性传递给 psake 时

psake TestProperties -properties @{"tags"="test"}

我收到以下错误:

PS D:\projects\WebTestAutomation> psake TestProperties -properties @{"tags"="test"}
"& 'C:\Chocolatey\lib\psake.4.2.0.1\tools\\psake.ps1' TestProperties -properties System.Collections.Hashtable
C:\Chocolatey\lib\psake.4.2.0.1\tools\psake.ps1 : Cannot process argument transformation on parameter 'properties'. Cannot convert the "System.Collections.Hashtable" value of
 type "System.String" to type "System.Collections.Hashtable".
At line:1 char:80
+ & 'C:\Chocolatey\lib\psake.4.2.0.1\tools\\psake.ps1' TestProperties -properties <<<<  System.Collections.Hashtable; if ($psake.build_success -eq $false) { exit 1 } else { e
xit 0 }
    + CategoryInfo          : InvalidData: (:) [psake.ps1], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,psake.ps1

关于如何克服这个问题的任何想法?

【问题讨论】:

    标签: psake chocolatey


    【解决方案1】:

    我通过将属性Hashtable 作为string 传递来解决这个问题。

    psake TestProperties -properties "@{tags='test'}"
    

    我还建议从命令提示符而不是 powershell 运行命令。因为psake 命令通过调用.bat 文件来工作,然后该文件调用.cmd,后者又执行.ps1 文件,因此在从powershell 执行命令时,在属性中使用与号会导致问题。

    例如,以下命令从命令提示符成功运行,但从 powershell 控制台运行时出错:

    psake TestProperties -properties "@{tags='test^&wip'}"
    

    注意使用^ 来转义&amp; 字符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-27
      • 2020-11-13
      • 1970-01-01
      • 1970-01-01
      • 2022-11-05
      相关资源
      最近更新 更多