Question:
I have a simple psake script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
properties { $SolutionDir = "SOLUTIONDIR" # Resolve-Path ".\src" $Config = "Debug" $DeployBaseDir = "$SolutionDir\RMSS.Setup.WiX\bin\$Config" $InstallerName = "RMSForMoversSuite_2_0_0" } task default -depends Test task Test { "CONFIG = $Config" "SOLUTIONDIR = $SolutionDir" "DEPLOYBASEDIR = $DeployBaseDir" } |
And I am calling it from the command line like this:
& .\psake.ps1 .\deploy.ps1 -properties @{"Config"="Staging"}
I would expect $DeployBaseDir
to be equal to SOLUTIONDIR\RMSS.Setup.WiX\bin\Staging
But instead, I get this output:
1 2 3 4 |
CONFIG = Staging SOLUTIONDIR = SOLUTIONDIR DEPLOYBASEDIR = SOLUTIONDIR\RMSS.Setup.WiX\bin\Debug |
Can anyone tell me what’s happening, why, and how to get the behavior I expect?
Answer:
From here http://codebetter.com/jameskovacs/2010/04/12/psake-v4-00/
Support for Parameters and Properties
Invoke-psake has two new options, –parameters and –properties. Parameters is a hashtable passed into the current build script. These parameters are processed before any ‘Properties’ functions in your build scripts, which means you can use them from within your Properties.
1 2 3 4 5 6 7 8 9 |
invoke-psake Deploy.ps1 -parameters @{server=’Server01’} # Deploy.ps1 properties { $serverToDeployTo = $server } task default -depends All |
Parameters are great when you have required information. Properties on the other hand are used to override default values.
1 2 3 4 5 6 7 8 9 |
invoke-psake Build.ps1 -properties @{config='Release'} # Build.ps1 properties { $config = 'Debug' } task default -depends All |
So you could either take $Config out of the properties and pass it in as a parameter.
Or take the $DeployBaseDir out of the properties and create it inside the task block