Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net MVC MvcBuildViews increasing compile time drastically

We have a project and would like to build the views to generate compile time errors if there is anything wrong within the Views' .cshtml files.

Still, compile time increases drastically:

  • MvcBuildViews = true takes 62 seconds
  • MvcBuildViews = false takes 9 seconds

Is this something acceptable? Cause the increase is quite drastic in which we cannot stand having to wait for such compile times. Any way we can improve such compilation?

The project up till now consists around 130 Views & Partial Views (.cshtml files). Is this considered to be large / medium / small?

like image 802
Mark Cassar Avatar asked Feb 14 '13 02:02

Mark Cassar


2 Answers

Well I think having the possibility to compile the views is a good thing by itself but I cannot wait that long either. So what I prefer to do is to add that MvcBuildViews = true inside the ProperyGroup of Release so that you only Compile the views at the Release time and before deployment

The property group should look like this:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> 

So put your

<MvcBuildViews>true</MvcBuildViews>

Inside this Release block. this way you still compile your views once and not every time you try to debug...

like image 72
Aram Avatar answered Nov 10 '22 00:11

Aram


We struggled with the same problem. We began compiling Views in order to catch obvious issues that would creep up on us during Integration Tests and UX Tests. Even worse were the bugs that somehow crept into production.

But, as you noticed, our build times became intolerable. Like you, our developers build countless times and that became a major part of our day. We had jokes about testing after lunch so the build could be done while we were out.

We eventually moved to building before UX-tests.

Now we are moving toward pre-compiling. Only one guy on our team has adopted it for now and apparently pre-compiles are noticably better than builds (incremental vs total). And setup is basically a nuget fetch.

These articles should be a good start

http://stacktoheap.com/blog/2013/01/19/precompiling-razor-views-in-asp-dot-net-mvc-3/

http://blog.davidebbo.com/2011/06/precompile-your-mvc-views-using.html

like image 39
Dave Alperovich Avatar answered Nov 09 '22 22:11

Dave Alperovich