Freigeben über


Releasing to Multiple Environments with Web Deploy and Parameters file Tokenization

Build and Release Scenario:

This method uses a combination of the Web Deploy Parameters and the Tokenization task in Release Management to transform the parameters at the time of release in each environment. The web.config values are changed when the deployment occurs into the environment through the use of variables set in RM for the deployment environment. Follows the model explained in Colin's blog post and uses his extension to transforms the key values.

This method differs from the web.config transform method as it uses the Web Deploy parameters file within the VS project to define the parameters and creates the Web Deploy parameters file to use for the changing of the web.config values during the deployment. This allows for the creation of a single build artifact and the movement of build through the release pipeline and changing of the web.config values as it moves to each environment.

Visual Studio Project Requirements:

Add appSettings keys to Project:

image

Parameters File in Visual Studio:

This method requires a Parameters.xml file is added to the root of the Visual Studio project. This is a requirement to hold the parameters to tokenize.

clip_image001

Here are example parameters to start a new file:

image

Add the parameters to the file and ensure the default value is set to "__parameter__" for the tokenization process to complete. The second most important piece is the path to the key in the web.config file with the match property as shown above.

The modification to the Visual Studio project is completed and there are no other changes. Check changes into TFS.

TFS Build Definition:

Create the build definition and in the Visual Studio build, add the following MSBuild arguments:

/p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=$(Build.ArtifactStagingDirectory) /p:DeployOnBuild=true /p:DeployIisAppPath="Default Web site/FarmToken"

The optional parameter DeployIISAppPath allows for the name of the IIS web application to be changed on deployment.  /p:DeployIisAppPath="Default Web site/FarmToken" clip_image002

The MSBuild process creates the Web Deploy package and generate the Parameters file, which is config.SetParameters.xml

clip_image003

During the execution of the build process, the values in the Parameters.xml file are placed in the Config.SetParameters.xml file and this is used for the tokenization process on the release.

For instance, the Environment key value in the web.config has the value of Dev. The default value is obtained from the Parameters.xml file during the build and placed in the Config.SetParameters.xml file.

Verify the SetParameters.xml file has the correct parameters created and values

clip_image004

Release Management Definition:

Download the Colin's ALM Corner Build and Release extension and enable

The release definition will have the following steps:

  • Replace tokens in the SetParameters.xml file with the correct values for the environment
  • Copy the Web Deploy package to a location on the IIS server, like C:\Deployments\Latest
  • Run the Web Deploy package command to update the website files

clip_image001[4]

Replace Token Task:

Select the folder in the Drop folder where the build artifacts are stored:

clip_image002[5]

Change the search pattern to the SetParameters.xml file

clip_image003[4]

Keep all other defaults.

Copy Files Task:

Set the location of the Web Deploy package on the IIS server. Can either copy to each machine in the farm. Or, copy to gold server and deploy. Test, and then use Web Deploy to copy to the other servers in the farm. This requires an additional batch file for the Web Deploy command.

clip_image004[6]

Batch File Script to Deploy:

This script is part of the Web Deploy package and calling the /Y switch to overwrite files in the web site.

clip_image005 clip_image006

Add the Environment Variables:

For each variable in the Parameters.xml file, add a variable to the environment. The RM tokenizer will replace the value in the Parameters.xml file with the variable value.

Use Release scoped variables in order to reuse the variables for each of the environments:

clip_image007

Can add a Variable Group to each environment

Prepare SetParameters.xml

The Config.deploy.cmd will perform the actual web.config updates and other areas of the website at the point of the deployment of the website. The SetParameters.xml file will contain the correct values to apply to the website.

Can use the command file created by the build process, or create own file to use to update the website.

Verify the Replacements in Parameter File was successful:

Check the Replace Tokens task in the logs

clip_image008

SetParameters.xml Final Values clip_image009

Update Website w/Web Deploy Command

The Batch Script executes the

C:\_Agent\LatestDeployments\FarmDemo_Token\LatestPackage\DemoWebFormsApp.deploy clip_image010

Set Destination IIS Web Application:

If the web application name can be specified at the time publishing through Web Deploy or set as a parameter in the SetParameters.xml file in the MSBuild arguments at the time the build package is created.

Comments