【发布时间】:2012-09-26 02:55:26
【问题描述】:
我在 MVC 3.0 项目中遇到了这个奇怪的间歇性错误 当我构建项目时,有时会收到以下错误消息:
无法识别的属性“xmlns:xdt”。请注意,属性名称是 区分大小写。
这是指标准的 web.config 转换文件(Web.Release.config 复制在下面) 没有其他错误或警告。这发生在调试模式和发布中。 如果我清理解决方案,有时它会清除
开始更新
发现问题。在 MVC 项目文件 (MyProject.csproj) 中,我将构建视图设置为 true
<MvcBuildViews>true</MvcBuildViews>
一旦放回 false,上述错误就会消失。我希望构建视图,因为它可以阻止很多愚蠢的视图代码错误等,并且是性能增强(页面是预编译而不是 jit)
有人知道这是什么原因导致的错误吗?这是一个错误吗?
结束更新
<?xml version="1.0"?>
<!-- For more information on using Web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an atrribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your Web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
【问题讨论】:
-
上面的web.release.config和MS提供的完全一样
-
我从未接触过 MvcBuildViews,它默认为 false。这个错误突然出现
-
@AndrewHarry 很高兴将其中一个答案标记为正确,毕竟这段时间 =)
-
@AndreCalil 我会将一个标记为“答案”,但正如你所说,这是很久以前的事了,我不知道哪个是最好的
-
@AndrewHarry 请注意,您假设 MvcBuildViews 可以防止服务器上的“jitting”(或代码生成 + 编译 + jitting 真的)。请注意,它实际上并没有做任何这些事情。它仅有助于验证您的构建。看到这个线程 - stackoverflow.com/questions/383192/compile-views-in-asp-net-mvc