Web.config transformation deployment in VS2010

Discussion created by VKamakodu on Aug 18, 2009
Latest reply on Aug 18, 2009 by VKamakodu

VS 2010 has a new deployment model called web config transformations. If you ever developed web applications, you would know some of the pains involved in deploying web config files to various server environments. Most of the time it has more to do with miscommunication/lost in transaltion kind of situation between developers and server admins than the actual deployment itself. Most of the time, You just have to modify the environment specific connection strings and some app settings. But even if that's not working well, then here's the new model.


To begin with, you can see that vs 2010 has 2 new files under Web.config. These 2 are included by default - Web.Debug.config and Web.Release.config.


The release.config looks like this (debug.config has no changes). Notice that it has the transformation to remove the debug attribute (you don't want debug attribute = true in your release versions).


<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">




<compilation xdt:Transform="RemoveAttributes(debug)"/>






That's all good. but how about having web.configs for all the other environments such as staging, testing etc?


Assuming that you have connection string in your parent web.config like shown below:
<add name="personalDB" connectionString="Server=devBox; Database=personal; User Id=admin; password=devPersonalPassword" providerName="System.Data.SqlClient"/>


Here's how you do it: Go to Build->Configuration Manager and add a new value called 'Staging' to the active solution configuration dropdown. Then right click on the web.config in the solution explorer and hit 'Add Config Transforms'. You can now see web.config.staging file added. Now add this to the staging.config file. All this is saying is, replace the connection string in the parent web.config with the changed value (notice server name etc).


<add name="personalDB" connectionString="Server=StagingBox; Database=personal; User Id=admin; password=StagingPersonalPassword" providerName="System.Data.SqlClient" xdt:Transform ="Replace" xdt:Locator="Match(name)" />


The final step is to run the msbuild task on your command prompt: <your project path> /t:TransformationWebConfig /p:Configuration=Staging


You repeat this on all your various config files.


You can also read my other article on VS2010 at http://vcampus.osisoft.com/forums/t/302.aspx