psake/psake — pull request #31 by idavis (2012-05-09 00:05:29+00:00)
Title: Allow scriptblock execution for initialization step

The patch includes an integration test and adds the -init / -initialization option to the psake command line adding the ability to pass a scriptblock that will run after the parameters and properties blocks.

The parameters and properties blocks only allow name/value pairs for initialization. This update allows us to override complex types.

I prefer to use variables that are built off of hashtables like the psake context to create a cleaner DSL. With this patch I can now override the following example 'variables':

properties {
$msbuild = @{}
$msbuild.logfilename = "MSBuildOutput.txt"
$msbuild.logfilepath = $build.dir
$msbuild.build_in_parralel = $true
$msbuild.logger = "FileLogger,Microsoft.Build.Engine"
$msbuild.platform = "Any CPU"
}

I think that this improves readability and allows us to group variables by intent.

example:
invoke-psake \build.ps1 -Initialization {
if(!$container) { $container = @{}; } # this is needed for each container variable you with to use.
$container.bar = "bar" # complex 'namespaced' variable override
$container.baz = "baz" # adds a new 'namespaced' value
$bar = 2 # simple value override
$baz = 3 # new simple value
}