我有以下 psake 脚本

properties {
    $ApplicationName = "test"
    $ApplicationPath = "c:\this\is\$ApplicationName"
}

Task test {
    "ApplicationName = $ApplicationName"
    "ApplicationPath = $ApplicationPath"
}

我只想将 ApplicationName 传递给脚本,以避免键入整个应用程序路径。但是当我使用 -parameters 标志时,属性没有变化
Invoke-psake .\script.ps1 -parameters @{ApplicationName = "another_test"} test

ApplicationName = test
ApplicationPath = c:\this\is\test

这听起来不对,因为应该在任何属性块之前评估参数。当我使用 -properties 标志时,应用程序名称已更改,但路径未更改
Invoke-psake .\script.ps1 -properties @{ApplicationName = "another_test"} test

ApplicationName = another_test
ApplicationPath = c:\this\is\test

所以属性已经被初始化了,但是 -parameters 不应该覆盖这个行为吗?

最佳答案

问题是您希望在属性块之前评估参数,但在 psake 中,属性会覆盖参数。

https://github.com/psake/psake/wiki/How-can-I-pass-parameters-to-my-psake-script%3F

properties {
  $my_property = $p1 + $p2
}



我不确定您是否可以在不修改 psake 的情况下覆盖一个属性并根据该属性更新进行另一个属性更新。您可以做的只是创建一个在需要时评估路径的函数:
Function ApplicationPath {"c:\this\is\$ApplicationName"}

关于psake - 如何在 psake 中正确使用 -parameters 和 -properties?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22380962/

10-14 09:16