Web.Config Transforms
November 9, 2010 Leave a comment
I wanted to dig into Web.Config transformations a bit more. I read a couple of articles here and here and decided to try it in a “Hello World” MVC2 project. I created a new MVC2 project and found the two Web.xxx.config files:
I then created a new setting variable in the Web.Config file:
1 <appSettings> 2 <add key="myValue" value="default"/> 3 </appSettings> 4
I then added a transform to the Debug and Release Files.
Debug:
1 <appSettings> 2 <add key="myValue" value="Debug" xdt:Transform="SetAttributes" xdt:Locator="Match(myValue)"/> 3 </appSettings> 4
Release:
1 <appSettings> 2 <add key="myValue" value="Release" xdt:Transform="SetAttributes" xdt:Locator="Match(myValue)"/> 3 </appSettings> 4
I then added some code to show the value on the main page:
1 public ActionResult Index() 2 { 3 ViewData["Message"] = String.Format("The Value in Web.Config is {0}", ConfigurationManager.AppSettings["myValue"].ToString()); 4 5 return View(); 6 } 7
I then hit F5, expecting the Debug value replace the default value in the web.config
Darn, the transform is not being recognized.