Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform web.config for Azure Website Deployment for each release environment

In Visual Studio Team Services (was Visual Studio Online), I have three release environments each with an Azure Website Deploy step.

I can transform the web.config for the build step by specifying the "BuildConfiguration" variable (e.g. Uat) which picks up the Web.Uat.config.

However I have multiple release environments that use this build configuration which all need to transform the web config (e.g. Dev,Test,Uat,Live).

Is it possible to specify the the web config transform to use for each release environment before the Azure Website deploy step?

Note: I realise that simple appsettings and connectionstrings can be specified in the Azure Portal under "All Settings" for the website but I need to do much more than transform these simple settings and already have configured the web config transforms for each environment within my solution

like image 809
Dan Cook Avatar asked May 16 '16 17:05

Dan Cook


2 Answers

The tokenizer task which comes as a part of Release Management Utility Tasks allows to transform config files depending upon the environment.

A single JSON config file containing all the configuration for all the environments can be used and the task will automatically pick up the right configuration depending upon the environment.

{
  "<environment>": {
    "CustomVariables": {
    "Variable1": "value1",
    "Variable2": "value2",
  },
    "ConfigChanges": [
        {
          "KeyName": "/configuration/appSettings/add[@key='ServiceURL']",
          "Attribute":"value",
          "Value":"https://ServiceURL"
        },
        {
          "KeyName": "/configuration/appSettings/add[@key='EnableDebugging']",
          "Attribute":"value",
          "Value":"false"
        },
        {
          "KeyName":“/configuration/connectionStrings/add[@name='databaseentities']”,
          "Attribute": "connectionString",
          "value": "Integrated Security=True;Persist Security Info=False;Initial Catalog=DB;Data Source=servername"
        }
    ]
}

Like this you can have many environments and their configuration in a single JSON file and the tokenizer task will modify your config depending upon the environment on which the deployment is going on.

Read the details on the above link to know more.

like image 86
Harshil Lodhi Avatar answered Sep 27 '22 20:09

Harshil Lodhi


Web.config is transformed during the build process, if you generate the deployment package from "Build" and then deploy it in "Release", then you cannot transform it before deployment.

You can use Web Deploy Parameterization to update the values in web.config before deployment. More information for your reference: Web Deploy Parameterization vs Web.config Transform.

And you can also use Replace Tokens task to replace the values in web.config file before deployment.

like image 23
Eddie Chen - MSFT Avatar answered Sep 27 '22 19:09

Eddie Chen - MSFT