在asp.net mvc3中編譯視圖檔案

來源:互聯網
上載者:User
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.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.