< Back

TaskSetup

Sun Jan 19, 2020 5:58 pm

NAME TaskSetup



SYNOPSIS

Adds a scriptblock that will be executed before each task





SYNTAX

TaskSetup [-setup] <ScriptBlock> [<CommonParameters>]





DESCRIPTION

This function will accept a scriptblock that will be executed before each task in the build script.



The scriptblock accepts an optional parameter which describes the Task being setup.





PARAMETERS

-setup <ScriptBlock>

A scriptblock to execute



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>A sample build script is shown below:



Task default -depends Test



Task Test -depends Compile, Clean {

}



Task Compile -depends Clean {

}



Task Clean {

}



TaskSetup {

"Running 'TaskSetup' for task $context.Peek().currentTaskName"

}



The script above produces the following output:



Running 'TaskSetup' for task Clean

Executing task, Clean...

Running 'TaskSetup' for task Compile

Executing task, Compile...

Running 'TaskSetup' for task Test

Executing task, Test...



Build Succeeded









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>A sample build script showing access to the Task context is shown below:



Task default -depends Test



Task Test -depends Compile, Clean {

}



Task Compile -depends Clean {

}



Task Clean {

}



TaskSetup {

param($task)



"Running 'TaskSetup' for task $($task.Name)"

}



The script above produces the following output:



Running 'TaskSetup' for task Clean

Executing task, Clean...

Running 'TaskSetup' for task Compile

Executing task, Compile...

Running 'TaskSetup' for task Test

Executing task, Test...



Build Succeeded











RELATED LINKS

Assert

Exec

FormatTaskName

Framework

Get-PSakeScriptTasks

Include

Invoke-psake

Properties

Task

TaskTearDown