As it is described in the FileTransform task document. The variables defined in pipeline will be matched against the key
or name
entries in the appSettings, applicationSettings, and connectionStrings sections.
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 config transforms.
So you can add a name
attribute to the file
property in your config file. For example in below. I add a name attribute LogFile
:
<applicationSettings>
<log4net debug="true">
<appender name="appender1">
<file name="LogFile" value="log.txt"/>
</appender>
</log4net>
</applicationSettings>
Then you can define a variabled named LogFile
in Variables section of your azure devops pipeline. See below example:
variables:
LogFile: D:\Logs\log.txt
steps:
- task: FileTransform@1
inputs:
folderPath: $(System.DefaultWorkingDirectory)
fileType: xml
If you donot want to add a name
attribute to file
property. You can use Task Magic Chuncks to replace the value of file
property.
Set the transformations: configuration/configSections/applicationSettings/log4net/appender/file/@value": "D:\Logs\log.txt"
. See below example:
See here about how to transform XML files
steps:
- task: sergeyzwezdin.magic-chunks.magic.chunks.MagicChunks@2
displayName: 'Config transform'
inputs:
sourcePath: '$(System.DefaultWorkingDirectory)/path/to/app.config'
transformations: |
{
"configuration/configSections/applicationSettings/log4net/appender/file/@value": "D:\Logs\log.txt"
}