I have specific config files for specific environments (dev,qa,uat) and another root web.config. The deployed code reads web.config. So I've been trying to either copy the contents or rename the file in Azure Pipelines.
- task: CopyFiles@2
displayName: 'Copy Specific Config'
inputs:
SourceFolder: 'Client.WebApi.Core/Configs/Web.QA.config'
TargetFolder: '$(build.artifactstagingdirectory)\MainWebApi'
- task: CmdLine@2
inputs:
script: rename $(build.artifactstagingdirectory)\MainWebApi\Web.QA.config
$(build.artifactstagingdirectory)\MainWebApi\web.config
Another method:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
copy-item -path Client.WebApi.Core/Configs/Web.QA.Config -destination Client.WebApi.Core/web.config
TargetFolder: '$(build.artifactstagingdirectory)/MainWebApi'
I have tried various combinations like renaming then copying and copying and then renaming it, copying the contents into new web.config files etc What exactly should be used?
Did you try
- task: CmdLine@2
inputs:
script: ren $(build.artifactstagingdirectory)\MainWebApi\Web.QA.config
$(build.artifactstagingdirectory)\MainWebApi\web.config
You can follow these documents:
What exactly should be used?
You can use the built-in task called File transform to transform web.< environment >.config to web.config. And then, you can use "Copy files" task to copy web.config to $(build.artifactstagingdirectory)
.
Here are detailed steps:
Step1. You need to add a transform file, which is in the same path as the source file.
If you don't want to make any changes to result file, just create a xml file with one line of scirpt:
<?xml version="1.0"?>
If you want to make some changes, write the changes in the transform file. Here is an example.
Step2. In your pipeline, search and add a "File Transform" task.
You need to tick the "XML transformation" and in "Transformation rules", write foolowing script:
-transform {transform file} -xml {source file} -result Web.config
Step3. Search and add a "Copy Files" task. Copy Web.config file to $(build.artifactstagingdirectory)
.
Here is the yaml script for step2 and step3.
steps:
- task: FileTransform@1
displayName: 'File Transform: '
inputs:
folderPath: '{folder path}'
enableXmlTransform: true
xmlTransformationRules: '-transform {transform file} -xml {source file} -result Web.config'
fileType: xml
- task: CopyFiles@2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '{folder path}'
Contents: Web.config
TargetFolder: '$(build.artifactstagingdirectory)\MainWebApi'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With