How to use -parameters and -properties in psake correctly?
Asked Answered
V

1

6

I have the following psake script

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

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

I want to pass only the ApplicationName to the script, in order to avoid typing the whole application path. But when i use the -parameters flag no change is applied to the properties

Invoke-psake .\script.ps1 -parameters @{ApplicationName = "another_test"} test

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

Which doesn't sound right since parameters should be evaluated before any property block. When i use the -properties flag the application name is changed, but not the path

Invoke-psake .\script.ps1 -properties @{ApplicationName = "another_test"} test

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

So the properties have already been initialized, but shouldn't the -parameters override this behavior?

Vermouth answered 13/3, 2014 at 14:0 Comment(0)
L
9

The issue is you expect parameters to be evaluated before property blocks, but in psake, properties override parameters.

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

properties {
  $my_property = $p1 + $p2
}

“properties” function in the build script can override a parameter passed to the Invoke-psake function. In the example above, if the parameters hashtable was @{"p1"="v1";"p2"="v2";"my_property"="hello"}, then $my_property would still end up set to “v1v2”.

I'm not sure if you can override a property and have another property update based on that property update without modifying psake. What you could do is just create a function that evaluates the path when needed:

Function ApplicationPath {"c:\this\is\$ApplicationName"}
Lashelllasher answered 16/3, 2014 at 23:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.