Saturday, August 4, 2012

How to Dynamically Generate ,Transform, or Modify a web.config file (Config transformation)

Dynamic config transform can be used to automatically creating multiple version of web.config from a main config file. This techniques is used to creates build for different environments like DEV,TEST,Production.

How to implement Config Transform (dynamic config mapping ) (Step By step) 

 Create a simple ASP.Net Project

  • image
GO to Build>>Configuration Manager
  • image
Select new in drop down
  • image
Provide name of configuration like “Release.PROD”
Also select Base build definitions like “Release”
  • image
  • image
Now Click Close
Right Click on project >>Add Config Transform
  • image 
Now you will see new config generated as below
  • image
Now open the newly created configuration file >>Web.Release.Prod.config” and con comment following section
    image
Modify “name=MyDB” >> name="ApplicationServices" ( as defined in main config file)
image
Now you new transform is ready to use. Select new build type from drop down
  • image
Then Right Click on Project >>Publish , Provide necessary information and publish you project to destination as release Build
  • image
Check out the final configuration generated and deploy location it will have required tronsform
  • image
Further References
  1. Config transform provide more smart replacement syntax that can be found at http://msdn.microsoft.com/en-us/library/dd465326.aspx
  2. MSDN Articles http://msdn.microsoft.com/en-us/library/dd465318.aspx
  3. MSDN Videos http://msdn.microsoft.com/en-us/vstudio/ff801895.aspx

No comments:

Post a Comment