Geeks With Blogs

News Please visit me at my new blog!!

profile for Aligned at Stack Overflow, Q&A for professional and enthusiast programmers
"free in Christ Jesus from the law of sin and death." Romans 8:2 (ESV) Check out the Falling Plates video on YouTube.
more about the Gospel
And then listen to Francis Chan speaking at LifeLight in SD.



Programming and Learning from SD

One part of MVC Views that can cause problems is that the cshtml can cause run-time errors. This can lead to bugs in Production or found by QA that could be avoided if it was built when you build the project. Pre-compiling can be turned on to avoid those problems. You add this in the project file of your web application, by setting the <MvCBuildViews>true</MvcBuildViews> in the .csproj. See http://www.dotnetcurry.com/ShowArticle.aspx?ID=698 for more details.

Another reason to pre-compile views is to avoid the initial hit of compiling when the website is first hit after publishing. It also ensures that changes can’t be made on the server. I did this in ASP.Net Web Forms using the Web Deploy Project back in the day. (more information) The <MVCBuildViews> doesn’t create place holders on deployment as I first expected. A co-worker pointed out that we could use the aspNet compiler in a post build or in a command-line.

.\aspnet_compiler.exe -v / -p C:\testdeploy c:\testdeploy2

Then we found the option in the web project’s publish Settings in Visual Studio 2012 (I have Premium).

publish

After deployment, the views are just place holders. Opening it up in notepad they say “This is a marker file generated by the precompilation tool, and should not be deleted!”. You’ll also see many .compiled files in the bin directory. For example: _contactinfo.cshtml.c4daf601.compiled

Another reference:  http://haacked.com/archive/2011/05/09/compiling-mvc-views-in-a-build-environment.aspx

Posted on Tuesday, May 28, 2013 12:28 PM MVC | Back to top


Comments on this post: Pre-Compiling your MVC Views

# re: Pre-Compiling your MVC Views
Requesting Gravatar...
or you can use
https://razorgenerator.codeplex.com/
http://visualstudiogallery.msdn.microsoft.com/1f6ec6ff-e89b-4c47-8e79-d2d68df894ec
Left by Anon on May 29, 2013 8:31 AM

Your comment:
 (will show your gravatar)


Copyright © Aligned | Powered by: GeeksWithBlogs.net