我想在.NET 4上运行的ASP.NET MVC 2项目中使用Web.config转换。但是,我有一个问题:ASP.NET MVC 2和额外的Web.config文件中的Web.config转换
// 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)" />
我不断收到此错误:
Warning No element in the source document matches '/configuration/add[@name='MyDB']' C:\filePath\Web.Release.config
我缩小下来到浏览文件夹中的web.config文件。如果我给它一个connectionString,比如根Web.config文件中的一个,比一切都好,但这意味着我必须维护两个Web.config文件。有没有解决这个问题的方法?难道我做错了什么?
好的,在[SetAttributes(connectionString)]中添加parens不起作用并抛出一个错误。但是,我注意到我的问题是我没有在调试/发布配置文件中用 connectionStrings>包装 。我突然意识到,当我看着你的例子。因此,+1为你举个例子。 :) –
2010-12-23 02:11:41