psake Configuration File
psake loads a psake-config.ps1 file at the start of every build to set default values for your build environment. You can use this file to change psake's default build file name, framework version, task name format, output handlers, and more.
Most projects do not need a psake-config.ps1 file. psake's built-in defaults work well for the majority of use cases. Only create one if you need to change a specific default.
How psake Finds the Config File
psake searches for psake-config.ps1 in two locations, in order:
- The build script's directory — the folder containing the build file passed to
Invoke-psake - The psake module directory — the folder where
psake.psm1is installed
The first file found wins. If neither location contains a config file, psake uses its built-in defaults.
This means you can place a psake-config.ps1 next to your psakefile.ps1 to customize settings per-project, or place one alongside the psake module for machine-wide defaults.
Partial Overrides
Your config file does not need to set every property. psake initializes all properties to their defaults before loading your config file, so any property you omit keeps its default value. You only need to set the properties you want to change.
Configuration Properties
Inside psake-config.ps1, you set properties on the $config variable. Here is every available property:
| Property | Type | Default | Description |
|---|---|---|---|
buildFileName | string | "psakefile.ps1" | Default build file name when none is specified |
legacyBuildFileName | string | "default.ps1" | Fallback build file name (legacy support) |
framework | string | "4.0" | .NET Framework version to target |
taskNameFormat | string or scriptblock | "Executing {0}" | Format string or scriptblock for task name display |
verboseError | bool | $false | Show detailed error information |
coloredOutput | bool | $true | Enable colored console output |
modules | string[] | $null | Module paths to auto-load before build execution |
moduleScope | string | — | Scope for loaded modules |
outputHandler | scriptblock | (routes to outputHandlers) | Master handler that receives all output |
outputHandlers | hashtable | (see below) | Per-type output handlers |
Minimal Example
# Use a different default build file name
$config.buildFileName = "build.ps1"
# Target .NET 4.8
$config.framework = "4.8"
# Show detailed errors
$config.verboseError = $true
Task Name Formatting
taskNameFormat accepts either a format string or a scriptblock:
# Format string — {0} is replaced with the task name
$config.taskNameFormat = "Executing {0}"
# Scriptblock — receives the task name as a parameter
$config.taskNameFormat = {
param($taskName)
"Executing $taskName at $(Get-Date)"
}
Auto-Loading Modules
Use $config.modules to load PowerShell modules before any tasks run:
# Load all modules from a folder
$config.modules = @(".\modules\*.psm1")
# Load specific modules
$config.modules = @(".\modules\*.psm1", ".\my_module.psm1")
Output Handlers
psake routes all internal messages through configurable output handlers. For a full guide on customizing logging, see Custom Logging.
See Also
- Custom Logging — Override psake's output handlers
- Configuration Reference — Full reference for
Invoke-psakeparameters and build script settings - Structure of a psake Build Script — How build scripts are organized