Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Use this task to replace tokens with variable values in XML or JSON configuration files.
# File transform v2
# Replace tokens with variable values in XML or JSON configuration files.
- task: FileTransform@2
inputs:
folderPath: '$(System.DefaultWorkingDirectory)/**/*.zip' # string. Required. Package or folder. Default: $(System.DefaultWorkingDirectory)/**/*.zip.
#enableXmlTransform: true # boolean. XML transformation. Default: true.
#xmlTransformationRules: '-transform **\*.Release.config -xml **\*.config' # string. Optional. Use when enableXmlTransform == true. XML Transformation rules. Default: -transform **\*.Release.config -xml **\*.config.
#errorOnInvalidSubstitution: false # boolean. Error on empty files and invalid substitution. Default: false.
# Variable Substitution
#jsonTargetFiles: # string. JSON target files.
#xmlTargetFiles: # string. XML target files.
# File transform v2
# Replace tokens with variable values in XML or JSON configuration files.
- task: FileTransform@2
inputs:
folderPath: '$(System.DefaultWorkingDirectory)/**/*.zip' # string. Required. Package or folder. Default: $(System.DefaultWorkingDirectory)/**/*.zip.
#xmlTransformationRules: '-transform **\*.Release.config -xml **\*.config' # string. XML Transformation rules. Default: -transform **\*.Release.config -xml **\*.config.
# Variable Substitution
#jsonTargetFiles: # string. JSON target files.
#xmlTargetFiles: # string. XML target files.
folderPath
- Package or folder
string
. Required. Default value: $(System.DefaultWorkingDirectory)/**/*.zip
.
File path to the package or a folder.
Variables are Build and Release. Wildcards are supported.
For example, $(System.DefaultWorkingDirectory)/**/*.zip
. For zipped folders, the contents are extracted to the TEMP location, transformations executed, and the results zipped in original artifact location.
enableXmlTransform
- XML transformation
boolean
. Default value: true
.
Config transforms will be run prior to the Variable Substitution.
XML transformations are supported only for Windows platform.
xmlTransformationRules
- XML Transformation rules
string
. Optional. Use when enableXmlTransform == true
. Default value: -transform **\*.Release.config -xml **\*.config
.
Provides a newline-separated list of transformation file rules using the syntax:
-transform <pathToTransformFile> -xml <pathToSourceConfigurationFile>
. The result file path is optional, and if not specified, the source configuration file will be replaced with the transformed result file.
xmlTransformationRules
- XML Transformation rules
string
. Default value: -transform **\*.Release.config -xml **\*.config
.
Provides a newline-separated list of transformation file rules using the syntax:
-transform <pathToTransformFile> -xml <pathToSourceConfigurationFile>
. The result file path is optional, and if not specified, the source configuration file will be replaced with the transformed result file.
jsonTargetFiles
- JSON target files
string
.
Provides a newline-separated list of files to substitute the variable values. File names are to be provided relative to the root folder.
For example, to replace the value of ConnectionString
in the sample below, you need to define a variable as Data.DefaultConnection.ConnectionString
in the build or release pipeline (or release pipeline's environment).
{
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\SQLEXPRESS;Database=MyDB;Trusted_Connection=True"
}
}
}
Variable Substitution is run after configuration transforms.
Note: Only custom variables that are defined in build/release pipelines are used in substitution. Default/system defined pipeline variables are excluded. If the same variables are defined in the release pipeline and in the stage, then the stage variables will supersede the release pipeline variables.
xmlTargetFiles
- XML target files
string
.
Provides a newline-separated list of files to substitute the variable values. File names are to be provided relative to the root folder.
For XML, Variables defined in the build or release pipelines will be matched against the key
or name
entries in the appSettings
, applicationSettings
, and connectionStrings
sections of any config file and parameters.xml
.
Variable Substitution is run after configuration transforms.
Note: Only custom variables defined in build/release pipelines are used in substitution. Default/system defined pipeline variables are excluded. If the same variables are defined in the release pipeline and in the stage, then the stage variables will supersede the release pipeline variables.
errorOnInvalidSubstitution
- Error on empty files and invalid substitution.
boolean
. Default value: false
.
If selected, the pipeline fails if the target files are empty or if the substitution fails.
All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.
None.
What's new in File Transform version 2:
Use this task to apply file transformations and variable substitutions on configuration and parameters files. For details of how translations are processed, see File transforms and variable substitution reference.
Important
This task is intended for web packages and requires a web package file. It does not work on standalone JSON files.
-transform <path to the transform file> -xml <path to the source file> -result <path to the result file>
FabrikamService.exe.config
).Note
Only custom variables defined in build and release pipelines are used in substitution. Default and system pipeline variables are excluded.
Here's a list of currently excluded prefixes:
agent.
azure_http_user_agent
build.
common.
release.
system.
tf_
If the same variables are defined in both the release pipeline and in a stage, the stage-defined variables supersede the pipeline-defined variables.
See also: File transforms and variable substitution reference.
If you need XML transformation to run on all the configuration files named with pattern .Production.config
,
the transformation rule should be specified as:
-transform **\*.Production.config -xml **\*.config
If you have a configuration file named based on the stage name in your pipeline, you can use:
-transform **\*.$(Release.EnvironmentName).config -xml **\*.config
To substitute JSON variables that are nested or hierarchical, specify them using JSONPath expressions.
For example, to replace the value of ConnectionString in the sample below, you must define a variable
as Data.DefaultConnection.ConnectionString
in the build or release pipeline (or in a stage within the release pipeline).
{
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\SQLEXPRESS;Database=MyDB;Trusted_Connection=True"
}
}
}
Requirement | Description |
---|---|
Pipeline types | YAML, Classic build, Classic release |
Runs on | Agent, DeploymentGroup |
Demands | None |
Capabilities | This task does not satisfy any demands for subsequent tasks in the job. |
Command restrictions | Any |
Settable variables | Any |
Agent version | All supported agent versions. |
Task category | Utility |
Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register today