ASP.NET MVC 2 中的 Web.config 转换和额外的 Web.config 文件
我正在尝试在 .NET 4 上运行的 ASP.NET MVC 2 项目中使用 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)" />
我不断收到此错误:
警告源文档中没有元素匹配“/configuration/add[@name='MyDB']”C:\filePath\Web.Release.config
我将范围缩小到 Views 文件夹内的 Web.Config 文件。如果我给它一个连接字符串,例如根 Web.config 文件中的连接字符串,那么一切都很好,但这意味着我必须维护两个 Web.config 文件。有什么办法解决这个问题吗?我做错了什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定为什么视图文件夹中的 web.config 受到牵连,但从您收到的错误来看,听起来 web.config 中的元素与转换配置文件之间不匹配。
在 web.config 中,假设
是
的子级,您会这样做:在 web.debug.config 中
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
正如我已经说过的:
不要忘记从原始的“web.config”中手动复制“configuration”的所有其他属性,因为VS2012似乎不会自动执行此操作,因此不会匹配...
As I already said:
Don't forget to manually copy all the other attributes of "configuration" from the original "web.config", as it seems that VS2012 doesn't do it automatically, so there will be no match...