Search code examples
powershellpsake

Setting a Property Value in 1 task and use the updated value in another


In my psake build script, I have a property called $build_mode that I set to "Release".

I have 2 tasks; "Compile_Debug", "Compile_Release". In Compile_Debug, I change $build_mode to "Debug" and it works fine while that task executes; however, if I have a have another task execute that uses $build_mode afterwards, $build_mode is back to "Release".

Is there a way to globally change or set a variable in a Psake build script so that an updated value can be used between tasks?

(I'm trying to have 1 "test" or 1 "package" task instead of a "Test_Debug", etc.)

Code:

properties {
    $build_mode = "Release"
}

task default -depends Compile_Debug, Test

task Compile_Debug {
    $build_mode = "Debug"
    # Compilation tasks here that use the Debug value
}

task Test {
        # Test related tasks that depend on $build_mode being updated.
}

Solution

  • Why don't you pass the build mode as parameter to the tasks from the Invoke-Psake?

     Invoke-Psake "$PSScriptRoot\Deploy\Deploy.Tasks.ps1" `
            -framework $conventions.framework `
            -taskList $tasks `
            -parameters @{
                    "build_mode" = "Debug"
                }
    

    And in the tasks you can now use $build_mode