Question

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 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:

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?

Was it helpful?

Solution

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.

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.

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

OTHER TIPS

In case you still want to use default values for your properties and at the same time use parameters here is the sample how-to.

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 use of convention over configuration with the flexibility for old schoolers to keep using their config spaghetti.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top