Replace Tokens task
Visual Studio Team Services Build and Release extension that replace tokens in files with variable values.
Add a new task, select Replace Tokens from the Utility category and configure it as needed.
- Root directory: the base directory for searching files. If not specified the default working directory will be used.
- Target files: the absolute or relative newline-separated paths to the files to replace tokens. Wildcards can be used (eg:
**\*.configfor all config files in all sub folders).
- Files encoding: the files encoding used for reading and writing. The 'auto' value will determine the encoding based on the Byte Order Mark (BOM) if present; otherwise it will use ascii.
- Write unicode BOM: if checked writes an unicode Byte Order Mark (BOM).
- Action: specify the action to take on a missing variable.
- silently continue: the task will continue without displaying any message.
- log warning: the task will continue but log a warning with the missing variable name.
- fail: the task will fail and log the missing variable name.
- Keep token: if checked tokens with missing variables will not be replaced by empty string.
- Token prefix: the prefix of the tokens to search in the target files.
- Token suffix: the suffix of the tokens to search in the target files.
- Empty value: the variable value that will be replaced with an empty string.
- Escape type: specify how to escape variable values.
- Escape character: when using
customescape type, the escape character to use when escaping characters in the variable values.
- Characters to escape: when using
customescape type, characters in variable values to escape before replacing tokens.
If you want to use tokens in XML based configuration files to be replaced during deployment and also have those files usable for local development you can combine the Replace Tokens task with the XDT tranform task:
- create an XDT transformation file containing your tokens
- setup your configuration file with local developement values
- at deployment time
- inject your tokens in the configuration file by using your transformation file
- replace tokens in your updated configuration file
New in 3.0.0
- Breaking change: If you were using the character escaping feature you need to select
customin Escape values type parameter.
- Add support to escape JSON in variable values (contributed by Justin Gould)
- Add support to escape XML in variable values (contributed by Justin Gould)
ISO 8859-1encoding to File encoding (#67)
New in 2.3.0
- Add support to escape characters in variable values (#52)
New in 2.2.1
- Fix issue with backslash in default target files value on mac (#50)
New in 2.2.0
New in 2.1.0
- Add support for comma-separator in Target files (#35).
- Add Empty value parameter to allow token replacement with an empty string (#32).
New in 2.0.2
- Fix invalid file permissions after saving files.
New in 2.0.0
- Breaking change: Migrated code to typescript to support cross-platform agent. This change requires the use of an agent at least in version 2.105.0 which is not compatible with TFS 2015. If you need to install the task on TFS 2015, download the vsix from the repository: https://github.com/qetza/vsts-replacetokens-task/releases/download/v1.4.1/qetza.replacetokens-1.4.1.vsix
- Breaking change: File encoding parameter is now used when reading and writing files. Previously it was only used when writing.
- Breaking change: File encoding doesn't support 'utf-32' and 'utf-32 (big endian)' anymore.
- Breaking change: Target files parameter now only uses the new line as a separator for multi-values (previously it used new-line and semi-colon).
- Removed required Root directory, an empty value is equivalent to $(System.DefaultWorkingDirectory).
New in 1.4.1
- Fix missing method issue with new xplat agent (2.104.1)
New in 1.4.0
- Add variables expansion in variable values.
- Escape token prefix and suffix in regex pattern.
New in 1.3.1
- Fix wrong encoding constructors parameters.
New in 1.3.0
- Replaced parameter Fail on missing with Action in Missing variables group.
- Add Keep token parameter in 'Missing variables' group.
- Fix issue on empty file.
New in 1.2.0
- Add Root directory task parameter to configure file search root directory (contributed by Jesse Houwing).
- Update Target files task parameter to support newline-separator (contributed by Jesse Houwing).