tags:

views:

58

answers:

2

In MSBuild you can data drive target dependencies by passing a item group into a target, like so:

<ItemGroup>
    <FullBuildDependsOn Include="Package;CoreFinalize"
                        Condition="@(FullBuildDependsOn) == ''" />
</ItemGroup>

<Target Name="FullBuild"
        DependsOnTargets="@(FullBuildDependsOn)" />

If you don't override the FullBuildDependsOn item group, the FullBuild target defaults to depending on the Package and CoreFinalize targets. However, you can override this by defining your own FullBuildDependsOn item group.

I'd like to do the same in psake - for example:

properties {
    $FullBuildDependsOn = "Package", "CoreFinalize"
}

task default -depends FullBuild

# this won't work because $FullBuildDependsOn hasn't been defined yet - the "Task" function will see this as a null depends array
task FullBuild -depends $FullBuildDependsOn 

What do I need to do to data drive the task dependencies in psake?

A: 

That's not a use-case that we ever considered when implementing psake. Changing FullBuild's list of dependencies seems a bit odd and unmaintainable to me. You can accomplish the same thing by passing in a list of tasks to run from the command line.

./invoke-psake buildScript.ps1 Package, CoreFinalize

Or am I missing something?

James Kovacs
I knew you could do that. I would like to drive task dependencies by properties. That way I can have a standard set of dependencies among tasks and then be able to override them as-needed. I'm building a re-usable build script, and I'm trying to take the convention-over-configuration approach, but I still want to enable configuration options.
Jordan
+1  A: 

OK. I understand what you're trying to accomplish now. You can do this through regular PowerShell-fu.

$FullBuildDependsOn = "Package"
Invoke-psake buildScript.ps1

In buildScript.ps1:

if($FullBuildDependsOn -eq $Null) {
  $FullBuildDependsOn = "Package", "CoreFinalize"
}

properties {
  # Usual build properties here
}

task default -depends FullBuild

task FullBuild -depends $FullBuildDependsOn {}

task Package {}

task CoreFinalize {}

The key here is to use a normal PowerShell variable rather than using a psake property. HTH.

James Kovacs
Yes, I figured I could do that. Just wondered if there was a way to support it through the psake property system that I wasn't seeing. Thanks!
Jordan