Skip to main content

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.

note

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:

  1. The build script's directory — the folder containing the build file passed to Invoke-psake
  2. The psake module directory — the folder where psake.psm1 is 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:

PropertyTypeDefaultDescription
buildFileNamestring"psakefile.ps1"Default build file name when none is specified
legacyBuildFileNamestring"default.ps1"Fallback build file name (legacy support)
frameworkstring"4.0".NET Framework version to target
taskNameFormatstring or scriptblock"Executing {0}"Format string or scriptblock for task name display
verboseErrorbool$falseShow detailed error information
coloredOutputbool$trueEnable colored console output
modulesstring[]$nullModule paths to auto-load before build execution
moduleScopestringScope for loaded modules
outputHandlerscriptblock(routes to outputHandlers)Master handler that receives all output
outputHandlershashtable(see below)Per-type output handlers

Minimal Example

psake-config.ps1
# 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:

psake-config.ps1
# 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:

psake-config.ps1
# 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