Compile the View File in Asp.net mvc3

Source: Internet
Author: User
Why compiled views?

First of all I prefer. 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

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 onAspxAndCshtmlAs 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. cspoj file with vs.net or any other XML editor, locate<Mvcbuildviews>And change the valueTrue.

. Csproj < Mvcbuildviews > True </ Mvcbuildviews >

 

 

When you'll fist build the project if you have. 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 shoshould 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.