I have not looked into this for too long, but it seems that while you are declaring the variable $ in the properties {... here ...} or in Param (... here ...), so that psake can fill them, they come although everything is in order. You missed $ z. If they lack something fundamental in why do you use parameters and properties together?
default.ps1
properties { $a = $null, $b = $null, $c = $null, $w = $null, $x = $null, $y = $null, $z = $null } Task default -Depends BuildSolution Task BuildSolution -Depends Clean { Write-Host "Running BuildSolution" echo "x -> $x" echo "y -> $y" echo "z -> $z" } Task Clean { Write-Host "Running Clean" echo "a -> $a" echo "b -> $b" echo "c -> $c" }
call a sample code (psake installed via chocolate to c :)
Import-Module C:\ProgramData\chocolatey\lib\psake\tools\psake.psm1 Invoke-Psake .\default.ps1 BuildSolution -properties @{'a'="a";"b"="b";"c"="c";'x'="x";'y'="y";'z'="z"}
EDIT:
This is the Properties function Line 256 in psake.psm1, noticing that it takes the arguments of the script block and adds them to the properties array on the context stack found in $ psake, still the script blocks here
function Properties { [CmdletBinding()] param( [Parameter(Position=0,Mandatory=1)][scriptblock]$properties ) $psake.context.Peek().properties += $properties }
Line 372 of the Invoke-psake in psake.psm1 Loads your scope default.ps1 build script into scope (you are currently seeing your write-host calls, but no variables have been loaded)
. $psake.build_script_file.FullName
Line 394 and line 397 Loads script blocks from parameters and properties into scope.
foreach ($key in $parameters.keys) { if (test-path "variable:\$key") { set-item -path "variable:\$key" -value $parameters.$key -WhatIf:$false -Confirm:$false | out-null } else { new-item -path "variable:\$key" -value $parameters.$key -WhatIf:$false -Confirm:$false | out-null } }
...
foreach ($key in $properties.keys) { if (test-path "variable:\$key") { set-item -path "variable:\$key" -value $properties.$key -WhatIf:$false -Confirm:$false | out-null } }
Line 420 and 423 calls invoke-Task (line 198), which, in turn, uses the above variables, there is also a statement that the variables are not null in this function.
I do not think the expected use case involved loading these variables in the root area when the script is the first. As a result, it spills out write-host calls, so the design probably assumed that you would first declare the Task method so that the region could pass variables to it, and this should be noted.