Why doesn't psake value my property as I expect it to be?

I have a simple psake script:

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 call it from the command line as follows:

& .\psake.ps1 .\deploy.ps1 -properties @{"Config"="Staging"}

I would expect $DeployBaseDir be equal to SOLUTIONDIR\RMSS.Setup.WiX\bin\Staging

But instead, I get this output:

 CONFIG = Staging SOLUTIONDIR = SOLUTIONDIR DEPLOYBASEDIR = SOLUTIONDIR\RMSS.Setup.WiX\bin\Debug 

Can someone tell me what is happening, why and how to get the behavior that I expect?

+4
source share
2 answers

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 hash table passed to the current build script. These parameters are processed before any "Properties" functions in build scripts, which means that you can use them from your properties.

 invoke-psake Deploy.ps1 -parameters @{server='Server01'} # Deploy.ps1 properties { $serverToDeployTo = $server } task default -depends All 

The options are great when you have the information you need. Properties, on the other hand, are used to override the default values.

 invoke-psake Build.ps1 -properties @{config='Release'} # Build.ps1 properties { $config = 'Debug' } task default -depends All 

Thus, you can either take $ Config from the properties or pass it as a parameter.
Or take $ DeployBaseDir from the properties and create it inside the task block

+11
source

If you still want to use the default values ​​for your properties and at the same time use the parameters here, this is an example guide.

 properties { $SolutionDir = "SOLUTIONDIR" # Resolve-Path ".\src" $Config = if($config){$config} else {"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" } & .\psake.ps1 .\deploy.ps1 -parameters @{config="Staging"} 

(Tested using psake 4.3.2)

This encourages the use of convention versus the flexibility for older students to continue to use their spaghetti for configuration.

0
source

All Articles