如何在psake中正确使用-parameters和-properties?

时间:2014-03-13 14:00:30

标签: psake

我有以下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不应该覆盖这种行为吗?

1 个答案:

答案 0 :(得分:6)

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

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

properties {
  $my_property = $p1 + $p2
}
  构建脚本中的

“properties”函数可以覆盖参数   传递给Invoke-psake函数。在上面的例子中,如果   参数哈希表是@ {“p1”=“v1”;“p2”=“v2”;“my_property”=“hello”},   然后$ my_property仍然会设置为“v1v2”。

我不确定您是否可以覆盖属性并在不修改psake的情况下根据该属性更新进行其他属性更新。你能做的就是创建一个在需要时评估路径的函数:

Function ApplicationPath {"c:\this\is\$ApplicationName"}
相关问题