Calum
Calum

Reputation: 1889

Replace tokens in all .config files in an Azure Web App

I have set up my environment variables which are successfully replaced on the on-prem test environments using the Replace tokens in files task in a Deployment group phase. I am now deploying to an Azure App Service and I'm wondering how to achieve the token replacement given that the tokens are in the format: #{tokenname}# and I want to replace tokens in files that match the pattern: **/*.config. I've had a look at enabling XML variable substitution within the Azure App Service Deploy step but this doesn't seem to target all tokens in all config files.

Upvotes: 1

Views: 5760

Answers (1)

starian chen-MSFT
starian chen-MSFT

Reputation: 33728

The XML variable substitution of Azure App Service Deploy task is used to modify configuration settings and it tasks effect only on applicationSettings, appSettings, connectionStrings and configSections elements of configuration files.

For example:

Web.config:

<appSettings>
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobstructiveJavascriptEnabled" value="true" />
        <!-- Change AdminUserName in this line: --> 
        <add key="AdminUserName" value="XXX" />
        <!-- Change AdminPassword in this line: --> 
        <add key="AdminPassword" value="XXX" />
    </appSettings>

Release definition variables:

  1. AdminUserName = ProAdmin
  2. AdminPassword = ProPass

Then the value of AdminUserName and AdminPassword will be replaced to ProAdmin and ProPass.

XML variable substitution

Regarding your issue, you can still use Replace tokens task to replace the value (zip file need to be extracted to a folder), you can define the variables with the same name for different environments (Scope).

You also can use Azure App Service deploy task if you just need to replace the value in applicationSettings, appSettings, connectionStrings and configSections elements。

Upvotes: 1

Related Questions