Blog Detail

MS Release Management- Web.Config tokenization for website project

21 Dec 14
admin
No Comments

Introduction

Web.config tokenization/parameterization is one of the major part of releasing web applications across different environments. But when it’s coming to website type project in Visual Studio, it’s a real head ache. I have came across such situation and spend lot of time to find a practical solution to solve this issue. Here I am explaining a tricky method to tokenize web.config, which is partially manual but practically implemented for website type project through MSBuild and MS Release management 2013.

Why Tokenization for Website Projects?

One of the recommended way of web.config parameterization is through Parameters.xml and webdeploy. But this approach is only applicable for web application project in Visual Studio, as this is happening through project file(csproj/vbproj). As you may know, Website project don’t have a project file. Because of the same reason, 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

Tokens are used by release management to know part of text that needs replacement with specific values. For release management to recognize a token, it needs to be prefixed by two underscores (__) and post-fix by two underscores (__), for example __WelcomeText__. Standard transformation will be applied while 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.

Web.Token.Config

We need to add a new config file to the project, I named it as web.Token.config. This file is an exact copy of our web.config file. Only difference between web.config and web.Token.config is, web.Token.config will have tokens instead of original values. See the below screens for more clarity.
WebConfig
Picture 1
clip_image004
Picture 2
Picture 1 shows the original configuration file used for the development purpose and picture 2 is our token file with tokens instead of real values. These tokens will be replaced through RM tool, will explain in the upcoming sections.

TokenizeAndDeploy.bat

TokenizeAndDeploy.bat is batch file and this file is playing a key role in release process. There are two steps included in this file.
1. Replace web.config with web.Token.config
2. Copy build from the source location to the destination folder
clip_image006
Picture 3
You can see two lines in this batch file. First line copy and replaces the web.config file with web.Token.config. Second line will copy the published website from the build drop location to the destination folder, where destination folder is mentioned as an argument to the batch file. That is, %1% is a batch file argument and the value will be passed in the release template.

Create new component in Release Management Client

We need to create a new component in 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 which is under build drop location, see the screen below. Make sure that TokenizeAndDeploy.bat also kept under the website root folder, otherwise we need to mention the inner folder path in the next tab (Deployment).
RMComponentCraete
Picture 4
Deployment
Picture 5
In the Deployment tab:
Tool: No tool
Command: TokenizeAndDeploy.bat _InstallationPath__
(Value will be passed in the release template)
Timeout: Depends on the amount of files to be copied and the network speed, default will be 5 minutes
RMComponentConfigutaionVariables
Picture 6
Now our web.config contains all tokens and we need to replace the tokens with the values with respect to the target environment (ie, UAT, Production etc). Configuration Variables playing this role. We need to add variables for each tokens in our web.Token.config. Variable name should be exactly same as that of the token, ie one of our token is __DocumentPath__ so we have created variable DocumentPath. Select After Installation as the variable Replacement mode as shown in Picture 6.
Save & 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 Tokenize & Copy component to the tool box and drag and drop it to the server box of our deployment sequence.
clip_image014
Picture 7
clip_image016
Picture 8
Double click on the Tokenize & Copy component in Picture7 and we can see the input boxes to provide values for each configuration variables in Picture 8. Same component we can use with different Stages (UAT, Production, Client1 Client2 etc) 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 release management client.

Conclusion

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

Leave A Comment