This project is read-only.

RazorGenerator vs visual studio built in publish precompilation

May 9, 2013 at 10:14 AM
VS 2012 (and prev versions) has a built in publish feature when we can precompile our web application.

This built-in precompilaton works fine for cshtml. I can even package and deploy to azure a precompiled mvc site with razor, without issue. It is strange that nobody talks about this possibility.

I'm wondering how RazorGenerator is different from the built-in precompilation? Are there any benefits using it?
May 9, 2013 at 7:33 PM
Somebody brought up a similar question about the MvcBuildViews setting here - Like it says there, these are just different ways of achieving precompilation.

The primary advantages of RazorGenerator are:
  • you could use it as a VS custom tool which means you could get compilation errors as and when you edit your views.
  • Additionally, the way the traditional precompilation model (the one in the publish feature) works is by launching a fake ASP.NET app domain and then compiling files inside of it. This is significantly slower than what RazorGenerator does which is to call into the Razor parser
  • The generated code also plays well with unit testing. Check out the RazorGenerator.Testing package to see how that works.
May 10, 2013 at 7:42 AM
Thank you, so the final outcome (in performance wise) is the same. (Thanks for the link, I've already known that the mvcbuildsviews in the project file is only for verification, and not a real precompilation).

I've found that the razorgenartor very fast and promissing (I used the msbuild approach), and worked fine on the dev machine. Unfortunately when I deployed my app to azure, it always fails to start with a general exception. Also fails to start when only the razorgenrator.mvc.dll added as a reference, and the razorgenerator view engine not used at all! So for some reason azure (windows server 2012 web role) not likes razorgenerator dlls, very frustrating.
So I need to stick with the built in precomiplation:(
May 10, 2013 at 3:05 PM
That's unfortunate. Do you have any more specifics on what the exception is? Might help us figure out what's causing it.
May 12, 2013 at 9:24 PM
I will try to redeploy a staging test instance, and revert.
May 17, 2013 at 7:11 AM
It seems that RazorGenerator.Mvc.Dll tries to load MVC 3.0. But I'm not using MVC 3.0 instead 4.0! What can be the problem?

Here is the fusion log:

*** Assembly Binder Log Entry (5/17/2013 @ 6:06:45 AM) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from: D:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable E:\base\x64\WaIISHost.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Appbase = file:///E:/approot/bin
LOG: Initial PrivatePath = E:\approot\bin
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = RoleManager

Calling assembly : RazorGenerator.Mvc, Version=, Culture=neutral, PublicKeyToken=7b26dc2a43f6a0d4.

LOG: This bind starts in default load context.
LOG: Using application configuration file: E:\base\x64\WaIISHost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from D:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///E:/approot/bin/System.Web.Mvc.DLL.
LOG: Assembly download was successful. Attempting setup of file: E:\approot\bin\System.Web.Mvc.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
May 17, 2013 at 7:15 AM
Sounds like you're missing the binding redirect which normally comes with an MVC4 app. e.g. see here
May 17, 2013 at 7:25 AM
Edited May 17, 2013 at 7:26 AM
Not missing! (Checked azure instance deployed web.config via rdp)
May 17, 2013 at 7:53 AM
It seems that the problem is with role startup code (RoleEntryPoint), see:
Now trying to fix...
May 17, 2013 at 9:42 AM