• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

在asp.netmvc3中编译视图文件

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
Why compiled views?

First of all I prefer VS.NET to compile the cshtml code at build time because it will notice syntax errors like on any .cs file. Syntax errors are most important when I have to do a quick check-in of all my sources to repository and I need to make sure I will not crash the next test build. On a default project the views are parsed and compiled at runtime when you fist navigate to the url with your browser, in other word the load time of an action will take longer because of the compiler. I prefer to wait a little longer for Visual Studio to check and compile my views then to wait for each one while debugging.

How to

Fist step is to edit the .csproj file and set the MvcBuildViews value to true. This setting was available since MVC 1 and it works on aspx  and cshtml as well.  There are lots of articles on the web about this, all you have to do is unload or close the mvc project in vs.net, edit the .cspoj file with vs.net or any other xml editor, locate <MvcBuildViews>  and change the value to true.

.csproj
<MvcBuildViews>true</MvcBuildViews>

 

 

When you’ll fist build the project if you have a .edmx file inside a MsBuild error will pop-up about EntityDesignerBuildProvider assembly. In order to fix this error open your project web.config and tell MsBuild that it should skip the edmx file from compilation:

Web.config
<compilation debug="true" targetFramework="4.0">
  <buildProviders>
    <remove extension=".edmx"/>
  </buildProviders>

 

 

For more information on this topic check out these blog posts from Malcolm Sheridan and  K. Scott Allen

PS

Some times Visual Studio will fail to build with an error regarding IIS, in order to fix it, delete the content of the Obj/Debug folder or run the “Clean” command on your project.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
WebDev.WebServer40.exe改造,自己制作轻量级asp.net网站IIS服务发布时间:2022-07-10
下一篇:
Asp.NET与WebApi共享Session发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap