< Back
Task
Post
NAME Task
SYNOPSIS
Defines a build task to be executed by psake
SYNTAX
Task [-name] <String> [[-action] <ScriptBlock>] [[-preaction] <ScriptBlock>] [[-postaction] <ScriptBlock>]
[[-precondition] <ScriptBlock>] [[-postcondition] <ScriptBlock>] [[-continueOnError]] [[-depends] <String[]>]
[[-requiredVariables] <String[]>] [[-description] <String>] [[-alias] <String>] [<CommonParameters>]
Task [-name] <String> [[-action] <ScriptBlock>] [[-preaction] <ScriptBlock>] [[-postaction] <ScriptBlock>]
[[-precondition] <ScriptBlock>] [[-postcondition] <ScriptBlock>] [[-continueOnError]] [[-depends] <String[]>]
[[-requiredVariables] <String[]>] [[-description] <String>] [[-alias] <String>] [-FromModule] <String>
[[-requiredVersion] <String>] [[-minimumVersion] <String>] [[-maximumVersion] <String>] [[-lessThanVersion]
<String>] [<CommonParameters>]
DESCRIPTION
This function creates a 'task' object that will be used by the psake engine to execute a build task.
Note: There must be at least one task called 'default' in the build script
PARAMETERS
-name <String>
The name of the task
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-action <ScriptBlock>
A scriptblock containing the statements to execute for the task.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-preaction <ScriptBlock>
A scriptblock to be executed before the 'Action' scriptblock.
Note: This parameter is ignored if the 'Action' scriptblock is not defined.
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-postaction <ScriptBlock>
A scriptblock to be executed after the 'Action' scriptblock.
Note: This parameter is ignored if the 'Action' scriptblock is not defined.
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-precondition <ScriptBlock>
A scriptblock that is executed to determine if the task is executed or skipped.
This scriptblock should return $true or $false
Required? false
Position? 5
Default value {$true}
Accept pipeline input? false
Accept wildcard characters? false
-postcondition <ScriptBlock>
A scriptblock that is executed to determine if the task completed its job correctly.
An exception is thrown if the scriptblock returns $false.
Required? false
Position? 6
Default value {$true}
Accept pipeline input? false
Accept wildcard characters? false
-continueOnError [<SwitchParameter>]
If this switch parameter is set then the task will not cause the build to fail when an exception is thrown by
the task
Required? false
Position? 7
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-depends <String[]>
An array of task names that this task depends on.
These tasks will be executed before the current task is executed.
Required? false
Position? 8
Default value @()
Accept pipeline input? false
Accept wildcard characters? false
-requiredVariables <String[]>
An array of names of variables that must be set to run this task.
Required? false
Position? 9
Default value @()
Accept pipeline input? false
Accept wildcard characters? false
-description <String>
A description of the task.
Required? false
Position? 10
Default value
Accept pipeline input? false
Accept wildcard characters? false
-alias <String>
An alternate name for the task.
Required? false
Position? 11
Default value
Accept pipeline input? false
Accept wildcard characters? false
-FromModule <String>
Load in the task from the specified PowerShell module.
Required? true
Position? 12
Default value
Accept pipeline input? false
Accept wildcard characters? false
-requiredVersion <String>
The specific version of a module to load the task from
Required? false
Position? 13
Default value
Accept pipeline input? false
Accept wildcard characters? false
-minimumVersion <String>
The minimum (inclusive) version of the PowerShell module to load in the task from.
Required? false
Position? 14
Default value
Accept pipeline input? false
Accept wildcard characters? false
-maximumVersion <String>
The maximum (inclusive) version of the PowerShell module to load in the task from.
Required? false
Position? 15
Default value
Accept pipeline input? false
Accept wildcard characters? false
-lessThanVersion <String>
The version of the PowerShell module to load in the task from that should not be met or exceeded. eg
-lessThanVersion 2.0.0 will reject anything 2.0.0 or higher, allowing any module in the 1.x.x series.
Required? false
Position? 16
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 {
"This is a test"
}
Task Compile -Depends Clean {
"Compile"
}
Task Clean {
"Clean"
}
The 'default' task is required and should not contain an 'Action' parameter.
It uses the 'Depends' parameter to specify that 'Test' is a dependency
The 'Test' task uses the 'Depends' parameter to specify that 'Compile' and 'Clean' are dependencies
The 'Compile' task depends on the 'Clean' task.
Note:
The 'Action' parameter is defaulted to the script block following the 'Clean' task.
An equivalent 'Test' task is shown below:
Task Test -Depends Compile, Clean -Action {
$testMessage
}
The output for the above sample build script is shown below:
Executing task, Clean...
Clean
Executing task, Compile...
Compile
Executing task, Test...
This is a test
Build Succeeded!
----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name Duration
---- --------
Clean 00:00:00.0065614
Compile 00:00:00.0133268
Test 00:00:00.0225964
Total: 00:00:00.0782496
RELATED LINKS
Assert
Exec
FormatTaskName
Framework
Get-PSakeScriptTasks
Include
Invoke-psake
Properties
TaskSetup
TaskTearDown
SYNOPSIS
Defines a build task to be executed by psake
SYNTAX
Task [-name] <String> [[-action] <ScriptBlock>] [[-preaction] <ScriptBlock>] [[-postaction] <ScriptBlock>]
[[-precondition] <ScriptBlock>] [[-postcondition] <ScriptBlock>] [[-continueOnError]] [[-depends] <String[]>]
[[-requiredVariables] <String[]>] [[-description] <String>] [[-alias] <String>] [<CommonParameters>]
Task [-name] <String> [[-action] <ScriptBlock>] [[-preaction] <ScriptBlock>] [[-postaction] <ScriptBlock>]
[[-precondition] <ScriptBlock>] [[-postcondition] <ScriptBlock>] [[-continueOnError]] [[-depends] <String[]>]
[[-requiredVariables] <String[]>] [[-description] <String>] [[-alias] <String>] [-FromModule] <String>
[[-requiredVersion] <String>] [[-minimumVersion] <String>] [[-maximumVersion] <String>] [[-lessThanVersion]
<String>] [<CommonParameters>]
DESCRIPTION
This function creates a 'task' object that will be used by the psake engine to execute a build task.
Note: There must be at least one task called 'default' in the build script
PARAMETERS
-name <String>
The name of the task
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-action <ScriptBlock>
A scriptblock containing the statements to execute for the task.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-preaction <ScriptBlock>
A scriptblock to be executed before the 'Action' scriptblock.
Note: This parameter is ignored if the 'Action' scriptblock is not defined.
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-postaction <ScriptBlock>
A scriptblock to be executed after the 'Action' scriptblock.
Note: This parameter is ignored if the 'Action' scriptblock is not defined.
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-precondition <ScriptBlock>
A scriptblock that is executed to determine if the task is executed or skipped.
This scriptblock should return $true or $false
Required? false
Position? 5
Default value {$true}
Accept pipeline input? false
Accept wildcard characters? false
-postcondition <ScriptBlock>
A scriptblock that is executed to determine if the task completed its job correctly.
An exception is thrown if the scriptblock returns $false.
Required? false
Position? 6
Default value {$true}
Accept pipeline input? false
Accept wildcard characters? false
-continueOnError [<SwitchParameter>]
If this switch parameter is set then the task will not cause the build to fail when an exception is thrown by
the task
Required? false
Position? 7
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-depends <String[]>
An array of task names that this task depends on.
These tasks will be executed before the current task is executed.
Required? false
Position? 8
Default value @()
Accept pipeline input? false
Accept wildcard characters? false
-requiredVariables <String[]>
An array of names of variables that must be set to run this task.
Required? false
Position? 9
Default value @()
Accept pipeline input? false
Accept wildcard characters? false
-description <String>
A description of the task.
Required? false
Position? 10
Default value
Accept pipeline input? false
Accept wildcard characters? false
-alias <String>
An alternate name for the task.
Required? false
Position? 11
Default value
Accept pipeline input? false
Accept wildcard characters? false
-FromModule <String>
Load in the task from the specified PowerShell module.
Required? true
Position? 12
Default value
Accept pipeline input? false
Accept wildcard characters? false
-requiredVersion <String>
The specific version of a module to load the task from
Required? false
Position? 13
Default value
Accept pipeline input? false
Accept wildcard characters? false
-minimumVersion <String>
The minimum (inclusive) version of the PowerShell module to load in the task from.
Required? false
Position? 14
Default value
Accept pipeline input? false
Accept wildcard characters? false
-maximumVersion <String>
The maximum (inclusive) version of the PowerShell module to load in the task from.
Required? false
Position? 15
Default value
Accept pipeline input? false
Accept wildcard characters? false
-lessThanVersion <String>
The version of the PowerShell module to load in the task from that should not be met or exceeded. eg
-lessThanVersion 2.0.0 will reject anything 2.0.0 or higher, allowing any module in the 1.x.x series.
Required? false
Position? 16
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 {
"This is a test"
}
Task Compile -Depends Clean {
"Compile"
}
Task Clean {
"Clean"
}
The 'default' task is required and should not contain an 'Action' parameter.
It uses the 'Depends' parameter to specify that 'Test' is a dependency
The 'Test' task uses the 'Depends' parameter to specify that 'Compile' and 'Clean' are dependencies
The 'Compile' task depends on the 'Clean' task.
Note:
The 'Action' parameter is defaulted to the script block following the 'Clean' task.
An equivalent 'Test' task is shown below:
Task Test -Depends Compile, Clean -Action {
$testMessage
}
The output for the above sample build script is shown below:
Executing task, Clean...
Clean
Executing task, Compile...
Compile
Executing task, Test...
This is a test
Build Succeeded!
----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name Duration
---- --------
Clean 00:00:00.0065614
Compile 00:00:00.0133268
Test 00:00:00.0225964
Total: 00:00:00.0782496
RELATED LINKS
Assert
Exec
FormatTaskName
Framework
Get-PSakeScriptTasks
Include
Invoke-psake
Properties
TaskSetup
TaskTearDown