如何将属性传递给巧克力版的psake

时间:2013-08-13 12:44:53

标签: psake chocolatey

我使用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

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

1 个答案:

答案 0 :(得分:5)

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

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

我还建议从命令提示符运行命令而不是PowerShell。因为psake命令通过调用.bat文件来工作,然后调用.cmd,而.ps1又执行psake TestProperties -properties "@{tags='test^&wip'}" 文件,在属性中使用&符导致命令时出现问题是从powershell执行的。

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

^

请注意使用&来转义{{1}}字符。

相关问题