i’m trying to use the Web.config transformations in my ASP.NET MVC 2 project running on .NET 4. However, I am having a problem:
// Root Web.config
<add name="MyDB" connectionString="default...default" />
// Root Web.Debug.config
<add name="MyDB" connectionString="debug...debug" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
// Root Web.Release.config
<add name="MyDB" connectionString="release... release" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
I keep getting this error:
Warning No element in the source document matches ‘/configuration/add[@name=’MyDB’]’ C:\filePath\Web.Release.config
I narrowed this down to the Web.Config file inside the Views folder. If I give it a connectionString, such as the one in the root Web.config file, than all is well, but that means I have to maintain two Web.config files. Is there any solution to this? Am I doing something wrong?
Not sure why web.config in the views folder is being implicated but from the error you’re getting it sounds like you’ve got a mismatch between the element in web.config and the transform config files.
In web.config, assuming
<add />is a child of<connectionStrings />you’d do:and in web.debug.config