5
votes

I am trying to update the configSource attribute on the appSettings element within my web.config file using web.config transformations.

I have the following in my web.config

    <appSettings configSource="Config\appSettings.local.config">
    </appSettings>

I want this to be

    <appSettings configSource="Config\appSettings.prod.config">
    </appSettings>  

when i build Release. This is not happening. I have the following in my Web.Release.config in the element

    <appSettings xdt:Transform="SetAttributes(configSource)" configSource="Config\appSettings.prod.config" />
2

2 Answers

13
votes

Transformations only happen when you deploy the web application (or create a deployment package). It does not happen when you simply build the solution.

http://msdn.microsoft.com/en-us/library/dd465326.aspx

"For Web application projects, ASP.NET provides tools that automate the process of changing (transforming) Web.config files when they are deployed."

3
votes

You can cause the transformation to happen on build if you like though, with a little poking around in your project file. I wrote a post on this a while back, its centered on app.config but it will work for web.config you can just miss a few steps out!

http://www.chrissurfleet.co.uk/post/2011/07/27/Faking-Webconfig-transformations-in-appConfig.aspx