razor 视图没有给出编译时错误 [英] razor views are not giving compile time error
问题描述
我最近安装了 VS 2012 Professional.
I've recently installed VS 2012 Professional.
当我尝试构建我的 MVC4 Web 项目时.当我执行构建"或重新构建"时,它无法识别剃刀视图中的错误.
When i try to build my MVC4 Web Project. It doesn't recognize error in razor view when i do "Build" or "Re-Build".
示例:
我从项目中删除了一个命名空间/或者说重命名了它.我构建了解决方案,它在所有 cs 文件中都给了我错误,我通过更改命名空间来修复这些错误.整个解决方案构建成功.当我运行该项目时,它给了我编译错误,说找不到命名空间,因为在某些视图(*.cshtml 文件)中仍然引用了旧命名空间.
Example :
I removed a namespace from the project / or say renamed it. i build the solution, it gave me errors in all cs files, which i fixed by changing the namespace. The entire solution build successfully. When i run the project it gave me Compilation Error saying that namespace not found, because the old namespace was still referred in some of the views (*.cshtml files).
预期的解决方案:
我希望当我执行构建"或重新构建"时,它应该能够识别出此类错误并将其他错误显示给我.
Expected Solution :
I wish when i do "Build" or "Re-Build", it should recognize such errors and show me along with any other errors.
这在 VS 2010 中运行良好,我是否缺少任何配置?
This was working fine with VS 2010, am i missing any configuration?
提前致谢!!阿米特
编辑我自己找到了答案,我认为发布问题还为时过早:
Edit I found the answer myself, i think it was early to post the question :
另一个问题
在 .csproject 文件中将值更改为 True 后,当我开始构建时它显示错误的项目,但一次只显示一个错误.比方说,我在总共 3 次查看中有 5 个错误.它只会给我看一个错误.是否有任何解决方案可以显示所有 5 个错误?
After changing value to True in .csproject file, when i start building the project it shows error, but it shows only one error at a time. let's say, i've 5 errors in total 3 views. it would just show me one error. Is there any solution so that it shows all the 5 errors ?
推荐答案
当我尝试构建我的 MVC4 Web 项目时.它不识别错误进行构建"或重新构建"时的剃刀视图.
When i try to build my MVC4 Web Project. It doesn't recognize error in razor view when i do "Build" or "Re-Build".
看起来很正常.Razor 视图由 ASP.NET 运行时动态编译.如果您希望在编译时构建您的视图,您可以将以下选项添加到您的 .csproj
文件中:
Seems normal. Razor views are dynamically compiled by the ASP.NET runtime. If you want your views to be built at compile-time you could add the following option to your .csproj
file:
<PropertyGroup>
<MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>
你可以看看这篇文章了解更多详情.
You may take a look at the this article for more details.
这篇关于razor 视图没有给出编译时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!