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

Cas*_*nge 4 psake chocolatey

我用Chocolatey安装了psake.这允许您使用psakepowershell或Windows命令行中的命令运行psake .

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

psake TestProperties -properties @{"tags"="test"}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

有关如何克服这一点的任何想法

Cas*_*nge 5

我通过将属性Hashtable作为a 来解决这个问题string.

psake TestProperties -properties "@{tags='test'}"
Run Code Online (Sandbox Code Playgroud)

我还建议从命令提示符运行命令而不是PowerShell.因为该psake命令通过调用一个.bat文件来工作,然后该文件调用一个文件然后.cmd执行.ps1文件,当从powershell执行命令时,使用属性中的"&"会导致问题.

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

psake TestProperties -properties "@{tags='test^&wip'}"
Run Code Online (Sandbox Code Playgroud)

注意使用^转义&字符.