Skip to main content

Structure of a psake Build Script

A psake build script contains calls to functions that the psake build engine will execute.

The functions are the following:

FunctionDescriptionRequired
Include()Call this function to have psake include the functions of another file into your scriptno
Properties()Call this function to set your propertiesno
Task()This is the main function that you write to execute a step in your build script. NOTE: There can be only one task function that is named "default" in your psake script and it cannot contain any code. psake will throw an exception if it finds more than one default task function or if the default task function contains codeyes
Exec()Call a command-line program and throw an exception if it returns a non-zero DOS exit codeno
Assert()Use to simplify writing conditional statementsno
FormatTaskName()Allows you to reformat how psake displays the currently running taskno
TaskSetup()A function that will run before each task is executedno
TaskTearDown()A function that will run after each taskno
BuildSetup()A script block that will run before the first task startsno
BuildTearDown()A script block that will run when either all tasks have completed, or the build has failedno

An example psake script:

Task default -Depends Test

Task Test -Depends Compile, Clean {
"This is a test"
}

Task Compile -Depends Clean {
"Compile"
}

Task Clean {
"Clean"
}

The following is a BNF for a psake build script:

<BuildScript> ::= <Includes> 
| <Properties>
| <FormatTaskName>
| <BuildSetup>
| <TaskSetup>
| <TaskTearDown>
| <Tasks>
<Includes> ::= Include <StringLiteral> | <Includes>
<Properties> ::= Properties <ScriptBlock> | <Properties>
<FormatTaskName> ::= FormatTaskName <StringLiteral>
<BuildSetup> ::= BuildSetup <ScriptBlock>
<BuildTearDown> ::= BuildTearDown <ScriptBlock>
<TaskSetup> ::= TaskSetup <ScriptBlock>
<TaskTearDown> ::= TaskTearDown <ScriptBlock>
<Tasks> ::= Task <TaskParameters> | <Tasks>
<TaskParameters> ::= -Name <StringLiteral>
| -Action <ScriptBlock>
| -PreAction <ScriptBlock>
| -PostAction <ScriptBlock>
| -PreCondition <ScriptBlock>
| -PostCondition <ScriptBlock>
| -ContinueOnError <Boolean>
| -Depends <TaskNames>
| -Description <StringLiteral>
<TaskNames> ::= <StringLiteral>, | <TaskNames>
<ScriptBlock> ::= { <PowerShellStatements> }
<Boolean> ::= $true | $false