Microsoft Release Management: Web.Config Tokenization For Website Project


Web.config tokenization/parameterization is one of the major parts of releasing web applications across various environments. But for website type projects in Visual Studio, it's a real headache. I have come across such a situation and spent a lot of time to find a practical solution to solve this issue. Here I am explaining a tricky method to tokenize web.config, that is partially manual but practically implemented for website type projects using MSBuild and Microsoft Release Management 2013.

Why Tokenization for Website Projects

One of the recommended methods of web.config parameterization is through Parameters.xml and webdeploy. But this approach is only applicable to web application projects in Visual Studio, since this is happening using the project file (csproj/vbproj). As you may know, Website projects don't have a project file. Due to that, Config Transforms also will not work for website projects.
Here I am explaining a customized method of web.config tokenization applicable for website projects.


Tokens are used by release management to understand the part of the text that needs replacement with specific values. For release management to recognize a token, it needs to be prefixed by two underscores (__) and post-fixed with two underscores (__), for example __WelcomeText__. Standard transformation will be applied when building on the Build server in order to have tokenized configuration files available in the drop location ready for release management to use during deployment.


We need to add a new config file to the project, I named it web.Token.config. This file is an exact copy of our web.config file. The only difference between web.config and web.Token.config is, web.Token.config will have tokens instead of the original values. See the following screens for more clarity.

Web Token Config
                                                                                 Picture 1

config file
                                                                                    Picture 2

Picture 1 shows the original configuration file used for the development purposes and Picture 2 is our token file with tokens instead of real values. These tokens will be replaced using the RM tool, I will explain in the future sections.


TokenizeAndDeploy.bat is a batch file and this file is playing a key role in the release process. There are two steps included in this file.

  1. Replace web.config with web.Token.config.

  2. Copy the build from the source location to the destination folder

                                                                              Picture 3

You can see two lines in this batch file. The first line copies and replaces the web.config file with web.Token.config. The second line will copy the published website from the build drop location to the destination folder, where the destination folder is specified as an argument to the batch file. That is, %1% is a batch file argument and the value will be ed in the release template.

Create new component in Release Management Client

We need to create a new component in the Release Management Client and this component will make use of our batch file to release our published site. We have to specify the source location of the published site and that is under the build drop location, see the screen below. Ensure that TokenizeAndDeploy.bat is also kept under the website root folder, otherwise we need to specify the inner folder path in the next tab (Deployment).

                                                                       Picture 4

Release Management Client
                                                                              Picture 5

In the Deployment tab:

  • Tool: No tool

  • Command: TokenizeAndDeploy.bat _InstallationPath__.
    (The value will be ed in the release template.)

  • Timeout: Depends on the amount of files to be copied and the network speed, the default will be 5 minutes.

Tokenize And copy
                                                                                 Picture 6

Now our web.config contains all the tokens and we need to replace the tokens with the values with respect to the target environment (in other words, UAT, Production and so on). Configuration Variables are playing this role. We need to add variables for each token in our web.Token.config. The variable name should be exactly the same as that of the token, in other words one of our tokens is __DocumentPath__ so we have created the variable DocumentPath. Select After Installation as the variable Replacement mode as shown in Picture 6.

Save and Close this component and we need to add this component in the release template.

Add Component to the Release template

Instead of XCopy deployer, we need to make use of the newly created component in our release template. Add a Tokenize and Copy component to the toolbox and drag and drop it to the server box of our deployment sequence.

Add Component
                                                                                 Picture 7

Release template
                                                                              Picture 8

Double-click on the Tokenize and Copy component in Picture7 and we can see the input boxes to provide values for each configuration variables in Picture 8. The same component we can use with various Stages (UAT, Production, Client1 Client2 and so on) in the release template. So from the next release onwards, our web.config will be properly updated with the Stage specific entries.

My previous articles may help you in case you have any confusions using the Release Management Client.


Here I have tried to explain one of my implementations of web.config tokenization that is applicable to website type projects in Visual Studio. It's hard to convert a website project to a web application, if the application is complex and big. This could help those people struggling to find a possible way to release website projects across multiple environments using TFS and Microsoft Release Management for Visual Studio 2013.

Thank you.

Similar Articles