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: **\*.config for 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).
Escape type: specify how to escape variable values. Value auto uses the file extension (.json and .xml) to determine the escaping and none as fallback.
Escape character: when using custom escape type, the escape character to use when escaping characters in the variable values.
Characters to escape: when using custom escape type, characters in variable values to escape before replacing tokens.
Verbosity: specify the level of log verbosity. (note: error and system debug are always on)
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.
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.2.1
Fix log issue with escaped secret values
New in 3.2.0
Switch to jschardet for encoding detection when selecting auto in File encoding (#99).