This project is read-only.
Project Description
This project extends the capabilities of the PrecompiledMvcViewEngine (part of Razor Generator project). It supports precompiled Razor views in multiple assemblies.

Getting Started

Get it from NuGet .


  • Controller action can return a compiled view from another assembly (which must be loaded and the view engine must know about it). Use the CompiledView attribute to decorate the action method like this
        [CompiledView(FromAssembly = "ClassLibrary1")]
        public ActionResult PluginView()
            return View("~/MyView.cshtml"); //MyView is a compiled view from the ClassLibrary1 assembly
  • If using a controller from another assembly (think plugin) the engine knows to return the view from that assembly.
For example, ClassLibrary1.dll (from the sample project) uses the default mvc application directory structure and it contains the Plugin1Controller class and the ~/Views/Plugin1/Index.cshtml view file. You can create it by copy/pasting the Controllers and Views directories from a standard mvc application.
  • Unobtrusive, it can be used with the default RazorViewEngine. You can have different action methods in the same controller which return
- A normal uncompiled view
- A compiled view from the same assembly
- A compiled view from another assembly

The source code contains a sample project which showcase different features.


You need the RazorGenerator tool VS extensions to compile the views.
This sample uses WebActivator to run the code before App_Start

[assembly: WebActivator.PreApplicationStartMethod(typeof(Activate), "Engine")]
namespace MvcApplication1
    public class Activate
         public static void Engine()
             var assemblies = new List<Assembly>();
             var current = Assembly.GetAssembly(typeof (MvcApplication));

             //get the dll containing compiled views            
             foreach(var file in Directory.EnumerateFiles(HostingEnvironment.MapPath(@"~\Compiled"),"*.dll"))
                     var a = Assembly.Load(AssemblyName.GetAssemblyName(file));
             //the view engine will consider all the provided assemblies          
             var engine = new PrecompiledMvcEngine(assemblies);

             ViewEngines.Engines.Insert(0, engine);

             // StartPage lookups are done by WebPages. 



Last edited Oct 28, 2011 at 7:32 AM by mike_sapiens, version 11