VSTS provides features to deploy your code to multiple servers using few configurations and deployment settings in release definition as follow.
I created Continuous Integration with VSTS and link the artifact to the release definition. I added two environments Staging and Production in the release definition.
Both have configured with Continuous Deployment using VSTS IIS deployment template. Now the problem is to configure appconfig or webconfig settings based on environment is selected by CD (Continuous Deployment) process so here we can get the help of parameters.xml file. This file is used to configure your parameters which have been replaced while deployment process. You can generate parameters.xml file from your web.config or app.config using the visual studio extension ParametersXmlGenerator. For example file content would be like as below:
<parameters> <parameter name="UTW5DB-Web.config Connection String" defaultValue="__ConnectionString__" > <parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/connectionStrings/add[@name='UTW5DB']/@connectionString" /> </parameter> <parameter name="UTW5ApiBaseUri" description="Description for UTW5ApiBaseUri" defaultvalue="__UTW5APIBASEURI__" tags=""> <parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='UTW5ApiBaseUri']/@value" /> </parameter> <parameter name="ClientBaseUri" description="Description for ClientBaseUri" defaultvalue="__CLIENTBASEURI__" tags=""> <parameterentry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='ClientBaseUri']/@value" /> </parameter> </parameters>
I also added replace token task which is available in VSTS marketplace, you need to download it into your VSTS account and place it on the top of the web deploy task. I also set prefix and suffix as per parameters.xml file as “_”.
In the artifact, you can find SetParameters.xml file which is transformed parameters.xml from source code and now need to add the path of that file in Replace tokens task as below:
Now the important part is to create environment specific variables in Variables section. In this section, you can define your scope to the particular environment.
These all variables are defined in SetParameters.xml file which is coming from artifact generated by CI build the package. The variable names should be matched with that file without suffix and prefix. After declaring those variables you need to set the path of SetParameters.xml file in Deploy web task.
Finally, when you run Continuous Deployment on the particular environment, automatically tokens have been replaced with defined variables and agent will run on the server to transform webconfig or appconfig.