Replacing the connection string in the Web.config during Azure pipeline release
04:26 28 Jan 2023

I have an old .NET project. I created an Azure Devops pipeline for it, a build and a deployment pipeline and I'll deploy it in 2 different environments.

I store some secret in Azure Keyvault, and the remaining parameters in Variable group.

Everything works perfectly, except for one thing: It's an old project, so I have a Web.config file and during release, I want to replace the environment-specific values, such as the connectionString or ApiKey.

I am able to successfully replace and change everything under the appSettings , but I am unable to replace the connectionString value under the connectionString.

Web.config file:




   
        
    
  
    
    
  

deployment.yml

                - task: AzureKeyVault@2
                  inputs:
                    azureSubscription: ${{ parameters.azureServiceConnection }}
                    KeyVaultName: ${{ parameters.keyvaultName }}
                    SecretsFilter: "*"
                    RunAsPreJob: false
                - task: IISWebAppManagementOnMachineGroup@0
                  inputs:
                    IISDeploymentType: IISWebsite
                    ActionIISWebsite: StopWebsite
                    StartStopWebsiteName: ${{ parameters.IIS_SiteName }}
                - task: IISWebAppDeploymentOnMachineGroup@0
                  inputs:
                    WebSiteName: ${{ parameters.IIS_SiteName }}
                    Package: $(Pipeline.Workspace)/**/${{ parameters.packageName }}
                    XmlVariableSubstitution: true

I have already tried using the FileTransform task and it did not work as expected.

How can I resolve this issue and make sure that the correct values are placed in my Web.config file?

asp.net azure azure-devops web-config web.config-transform