Override properties when including a psake script in an other psake script

958 Views Asked by At

I am new to psake and I have this issue: I have 2 psake scripts:

(1): base_tasks.ps1:

properties{ 

$a = "hello"

$b = "hi"

}

task One{
  Write-Host $a
}

(2): install.ps1

Include .\base_tasks.ps1

properties{ 

$a = "Goodbye"

$b = "Adjeu"

}

task default -depends One

Now, is it possible to override the properties and variables from file 1? I want to use file 1 as "base tasks" and use those tasks in the install.ps1 and override the properties. Or do I have to do that an other way? I will invoke install.ps1 and use my $a and $b from install.ps1.

  • DanceAlot
1

There are 1 best solutions below

1
On BEST ANSWER

From the source, it looks like Properties is just a function:

function Properties {
    [CmdletBinding()]
    param(
        [Parameter(Position=0,Mandatory=1)][scriptblock]$properties
    )
    $psake.context.Peek().properties += $properties
}

So when you call it again, it will just add the properties again.

The properties are then converted into variables like so:

foreach ($key in $properties.keys) {
        if (test-path "variable:\$key") {
            set-item -path "variable:\$key" -value $properties.$key | out-null
        }
    }