Skip to main content

Properties

This page was generated

Contributions are welcome in Psake-repo.

SYNOPSIS

Define a scriptblock that contains assignments to variables that will be available within all tasks in the build script

SYNTAX

ScriptBlock (Default)

Properties [-Properties] <scriptblock> [<CommonParameters>]

Hashtable

Properties [-Hashtable] <hashtable> [<CommonParameters>]

DESCRIPTION

A build script may declare a "Properties" function which allows you to define variables that will be available within all the "Task" functions in the build script.

EXAMPLES

EXAMPLE 1

Properties {
$build_dir = "c:\build"
$connection_string = "datasource=localhost;initial catalog=northwind;integrated security=sspi"
}
Task default -depends Test
Task Test -depends Compile, Clean {
}
Task Compile -depends Clean {
}
Task Clean {
}

Note: You can have more than one "Properties" function defined in the build script.

EXAMPLE 2

Properties {
$script:build_dir = "c:\build"
$script:connection_string = "datasource=localhost;initial catalog=northwind;integrated security=sspi"
}
Task Compile {
"Building to: $build_dir" # No PSScriptAnalyzer warning, variable is recognized
}

Recommended: Use script-scoped variables to avoid PSScriptAnalyzer warnings The $script: prefix has identical runtime behavior but satisfies PSScriptAnalyzer's static analysis requirements.

EXAMPLE 3

Properties {
$build_dir = "c:\build" # Warning: PSUseDeclaredVarsMoreThanAssignments
}
Task Compile {
"Building to: $build_dir" # Works at runtime, but PSScriptAnalyzer warns
}

Alternative: Non-scoped variables (generates PSScriptAnalyzer warnings)

Variables still work correctly at runtime, but PSScriptAnalyzer cannot detect that they will be used in tasks.

PARAMETERS

-Hashtable

An alternative to the scriptblock parameter, you can provide a hashtable of key-value pairs that will be converted into variables. This is useful when you want to define properties programmatically or from an external source.

Type: System.Collections.Hashtable
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Hashtable
Position: 0
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Properties

The script block containing all the variable assignment statements

Type: System.Management.Automation.ScriptBlock
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: ScriptBlock
Position: 0
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES

Properties scriptblocks are dot-sourced into each task's scope at runtime. Variables are not accessible outside of task scriptblocks.

PSScriptAnalyzer may flag declared variables as unused — this is a false positive. Use the $script: prefix to suppress it (see examples).

VERSION

This page was generated using comment-based help in Psake 5.0.4.