What is the structure of a psake build script?

Gary Ewan Park edited this page Mar 20, 2016 · 11 revisions

This wiki is now deprecated. Please see the latest documentation here

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

The functions are the following:

Function Description Required
Include() Call this function to have psake include the functions of another file into your script no
Properties() Call this function to set your properties no
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 code yes
Exec() Call a command-line program and throw an exception if it returns a non-zero DOS exit code no
Assert() Use to simplify writing conditional statements no
FormatTaskName() Allows you to reformat how psake displays the currently running task no
TaskSetup() A function that will run before each task is executed no
TaskTearDown() A function that will run after each task no

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> 
                | <TaskSetup> 
                | <TaskTearDown> 
                | <Tasks> 
<Includes> ::= Include <StringLiteral> | <Includes>
<Properties> ::= Properties <ScriptBlock> | <Properties>
<FormatTaskName> ::= FormatTaskName <Stringliteral>
<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

Next – How can I get help on how to use psake?