ASP.NET MVC has a somewhat hidden, but pretty well known setting to build views when building an MVC project.

This setting can be enabled and disabled in the csproj file, by opening it up in a text editor.

The setting is called 

<MvcBuildViews>false</MvcBuildViews>

By enabling the setting (replace false with true, duh :-), aspnet_compiler will be run to compile the views.
Enabling this setting is very useful, because otherwise code errors in the view do not get noticed until runtime, and might not be noticed in time.

However, there's downside: enabling this setting slows down your builds quite a bit.

There's a way to realize fast(er) builds on the developer machines, by letting the view compilation only happen on the CI builds.

 

If your developer builds are built using the Debug configuration, and CI builds happen using the Release configuration, you can change the .csproj file as follows:

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
    <MvcBuildViews>false</MvcBuildViews>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
    <MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>

Alternatively, you can also, set up a property especially for that, and then make sure msbuild is called with that property set to true.

Eg: 

<PropertyGroup>
    <EnableMvcBuildViews>false</Configuration>
</PropertyGroup>
 <PropertyGroup Condition="'$(EnableMvcBuildViews)' == 'true'">
    <MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>
Tags: , , | Categories:
blog comments powered by Disqus