Using psake 4.5.0 I've tried to run my default.ps1
file many different ways, passing both -properties
and -parameters
, but those values are just ignored in the root-scope of the .ps1
-script.
Execute relative (with psake in a subfolder):
.\psake-4.5.0\psake.ps1 .\default.ps1 BuildSolution -properties @{"a"="a";"b"="b";"c"="c";"d"="d"} -parameters @{"w"="w";"x"="x";"y"="y";"z"="z"}
Execute with imported module:
Import-Module .\psake-4.5.0\psake.psm1
Invoke-Psake .\default.ps1 BuildSolution -properties @{"a"="a";"b"="b";"c"="c";"d"="d"} -parameters @{"w"="w";"x"="x";"y"="y";"z"="z"}
Execute through installed Chocolatey-package:
psake .\default.ps1 BuildSolution -properties "@{'a'='a';'b'='b';'c'='c';'d'='d'}" -parameters "@{'w'='w';'x'='x';'y'='y';'z'='z'}"
Execute through cmd.exe
:
psake-4.5.0\psake.cmd default.ps1 BuildSolution -properties "@{'a'='a';'b'='b';'c'='c';'d'='d'}" -parameters "@{'w'='w';'x'='x';'y'='y';'z'='z'}"
Right now, the default.ps1
is simply just debugging all these values:
// Since "properties" doesn't get populated, I also try "Param"
Param(
$w = $w, // Trying to populate from passed param
$x = $null, // Trying to default to null-value
$y // Trying another syntax, hoping for population
// "$z" left out, hoping for population
)
properties {
$a = $a
$b = $null
$c
}
Write-Host "a: $a"
Write-Host "b: $b"
Write-Host "c: $c"
Write-Host "d: $d"
Write-Host "w: $w"
Write-Host "x: $x"
Write-Host "y: $y"
Write-Host "z: $z"
Task BuildSolution -Depends Clean {
Write-Host "Running BuildSolution"
}
Task Clean {
Write-Host "Running Clean"
}
The output is in all cases:
a:
b:
c:
d:
w:
x:
y:
z:
What is the proper syntax to pass properties
and/or parameters
to psake?
I did not look into this too long but it seems as long as you declare the $variable in properties { ... here ... } or in Param (... here ... ) so psake can populate them, they come though okay. You missed $z. Unless im missing something fundamental about why your using parameters and properties together?
default.ps1
invoke code sample (psake installed via chocolatey to c:)
EDIT:
This is the
Properties
function Line 256 in psake.psm1, notice it takes a scriptblock args and adds it to properties array on the context stack found on $psake, still script blocks hereLine 372 of
Invoke-psake
function in psake.psm1 Loads your default.ps1 build script to scope ( at this point you see yourwrite-host
calls but no variables loaded )Line 394 and Line 397 Loads the script blocks from parameters and properties to the scope.
...
Line 420 and 423 calls
invoke-Task
(Line 198) which in turn uses the variables defined above, also there is an assert that the variables are not null in this function.I don't think the expected use case involved loading these variables into root scope, when the script is first . sourced into scope it spits out the
write-host
calls then, design probably intended you to declare Task method first so the scope can pass the variables into it and it should be noted.