ASP.Net MVC MvcBuildViews Extends Compilation Time

We have a project and would like to create views to generate compile-time errors if there is something wrong with the .cshtml Views files.

However, compilation time increases dramatically:

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

Is this something acceptable? Because the increase is quite sharp, in which we can not wait to wait for such compilations. How can such a compilation be improved?

The project still consists of 130 views and partial views (.cshtml files). Is it considered large / medium / small?

+7
source share
3 answers

Well, I think being able to compile views is good on its own, but I can't wait too long. Therefore, I prefer to add MvcBuildViews = true inside the ProperyGroup Release, so that you only compile the views at the time of release and before deployment

The property group should look like this:

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

So put

 <MvcBuildViews>true</MvcBuildViews> 

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

+11
source

We struggled with the same problem. We started compiling Views to identify obvious issues that might sneak up on us during the integration tests and UX Tests . Even worse were the mistakes that somehow went into production.

But, as you have noticed, our assembly times have become unbearable. Like you, our developers build countless times, and this has become an important part of our day. We had jokes about testing after dinner, so the assembly could be completed while we were away.

As a result, we proceeded to the creation of UX tests .

Now we are moving to precompilation. At the moment, only one guy from our team accepted it, and, apparently, preliminary compilations are noticeably better than assemblies (step-by-step and final). And customization is basically 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

+2
source

Set MvcBuildViews to false in csproj to configure debugging.

 <MvcBuildViews Condition=" '$(Configuration)' != 'Debug' ">true</MvcBuildViews> 

Add the following external command to the Tools / External Tools menu

 Title: Compile with MVC views Command: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe Arguments: $(SolutionDir)$(SolutionFileName) /p:MvcBuildViews=true Initial directory: $(SolutionDir) Use Output window: checked 

Then add a shortcut to this: go to tools / options / environmentnement / keyboard Find the "Tools.ExternalCommandX" command, where X is the position of your external command to which you just added it. Assign a key (Ex: Ctrl-shift-1)

Now explanations: We have the same problem. We don’t want to compile the views most of the time, but we like to compile them before checking the code, so we collect the views 1 time out of 50 or something like that. To achieve this, I added an external tool command for msbuild with the mvcbuildviews parameter. The only drawback is that errors are not indicated in the error window of the visual studio, you need to look at the output window and double-click on the errors, if any.

0
source

All Articles