Server specific Web.config sections replacement with WDP
In this post I am hoping to explain how you can change your web.config settings per different server environment using Web Deployment Projects (WDP) for VS 2005 or VS 2008ā¦
First of all let me start with the fact that WDP for VS 2005 as well as WDP for VS 2008 are build configuration aware⦠In fact, special effort was made in WDP 2005 & WDP 2008 to allow configuration specific settingsā¦
That is the reason when you look at the WDP UI you can see configuration specific dropdowns as shown below:
You can create one build configuration per your server environment eg. āTestingā, āStagingā , āProductionā etc and configure all of your WDP settings per build configuration pretty easily⦠Learn more how to manage configurations per build environmentā¦
Next I want to change connectionStrings section in side the web.config for āTestingā server and āReleaseā server⦠The original connection String section in my web.config file looks as below:
<connectionStrings> <add name="vishal-db" connectionString="Data Source=vijoshi-DevBox; Initial Catalog=vishal-db; Integrated Security=True"/> connectionStrings>
For āTestingā environment I would like to change my Data Source to be vijoshi-Testing
For āReleaseā environment I would like to change my Data Source to be vijoshi-Release
To accomplish this I am going to add two configuration files to my project named connectionString.Testing.config and connectionString.Release.config⦠After adding the two files my solution explorer should look as below:
The content of connectionString.Testing.config file will look as below:
<connectionStrings> <add name="vishal-db" connectionString="Data Source=vijoshi-Testing; Initial Catalog=vishal-db; Integrated Security=True"/> connectionStrings>
Notice that the connectionString.Testing.config only contains connectionStrings section (as opposed to original web.config which may contain many other sections) ⦠Similar to the above example in connectionString.Release.config file I will only change the Data Source to vijoshi-Releaseā¦
After these two files are added I can now open my WDP configuration and go to the āDeploymentā node and check the āEnable Web.config file replacementāā¦Ā After this the only thing I need to do is write connectionStrings=connectionString.Testing.configĀ as shown belowā¦
Ā Ā After this when I build my WDP project the connectionStrings section will be replaced by the content of the connectionString.Testing.configā¦
Also now I can modify the Configuration from āTestingā to āReleaseā and set the Web.config file section replacements section to look as below
connectionStrings=connectionString.Release.configĀ
This way you can also modify the other config sections each in a new line of the text box shown aboveā¦
Hope this will helpā¦
-Vishal









