不,这仍然行不通。似乎 TC 无论如何都会将值视为字符串。也许答案来自允许这样做的 TC 版本,但最新版本没有。
没有冒号:
[16:18:37]Step 1/6: Migrate Up (Powershell)
[16:18:37][Step 1/6] PowerShell Executable: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
[16:18:37][Step 1/6] PowerShell arguments: [-NonInteractive, -ExecutionPolicy, ByPass, -File, C:\BuildAgent\work\f2797fec10821a01\data\Migration\MigrateUp.ps1, "data\change scripts", DB, xxxxxxx, sa, *******, -NoExec, $false]
[16:18:37][Step 1/6] C:\BuildAgent\work\f2797fec10821a01\data\Migration\MigrateUp.ps1 : A positional parameter cannot be found that accepts argument '$false'.
带冒号:
[16:18:37]Step 2/6: Migrate Up (Powershell)
[16:18:37][Step 2/6] PowerShell Executable: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
[16:18:37][Step 2/6] PowerShell arguments: [-NonInteractive, -ExecutionPolicy, ByPass, -File, C:\BuildAgent\work\f2797fec10821a01\data\Migration\MigrateUp.ps1, "data\change scripts", DB, xxxxxx, sa, *******, -NoExec:$false]
[16:18:37][Step 2/6] C:\BuildAgent\work\f2797fec10821a01\data\Migration\MigrateUp.ps1 : Cannot process argument transformation on parameter 'NoExec'. Cannot convert value "System.String" to type "System.Management.Automation.SwitchParameter". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0.
删除 [switch] 也不起作用,因为您给它的任何值都不会被视为布尔值 - 而是分配给布尔值的字符串 - 因此,所有布尔运算都将是 $true。
换句话说,您发送的任何内容都会如下所示:
- 0 => '0'
- 1 => '1'
- $false => '$false'
- $true => '$true'
(都不是== $false,但都等价于$true)
我不知道如何让 TC 接受布尔值!
我能做的最好的就是假设参数是一个字符串并在我的脚本内部使用 System.Convert.ToBoolean() ...