Web.Config Transforms

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:

image

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

image

Darn, the transform is not being recognized.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: