ASP.net MVC Compiled Views

ASP.net MVC Compiled Views

Big old pain in the arse when you get a runtime error from a view, more so if its then in the build server;

Simple solution though; pop open your UI/Web project (csproj) file in an editor of your choice. Check if it already contains an false tag (if it has set it to true)

If your missing it; add it as follows…

Find the That contains the following entries…

<RootNamespace>Project.UI.Web</RootNamespace>
<AssemblyName>Project.UI.Web</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<RestorePackages>true</RestorePackages>

and simply add

<MvcBuildViews>true</MvcBuildViews>

At the end of the file, uncomment the <Target Name="AfterBuild" section of the configuration. This should resemble…

<Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>

For extra points, ensure that EnableUpdatable is set to false, or the views wont be pre-compiled.

<EnableUpdatable>false</EnableUpdatable>

Why this isn't just a project-property option rather than more xml trawling is anyone's guess.

Caveats

Does Not Work With Umbraco (up to and including 6)

Chris McKee

Chris McKee

https://chrismckee.co.uk

Software Engineer, Web Front/Backend/Architecture; all-round tech obsessed geek. I hate unnecessary optimism