Deploying ASP.NET MVC 3 Razor – Missing System.Web.Helpers (and others)

Last week I was racing against time to complete a QA deployment of an ASP.NET MVC 3 application that uses the Razor view engine.

The deployment was to a clean Windows Server 2008 R2 box. I had already completed the following steps:

  • Used the Web Platform Installer to install “IIS 7 Recommended Configuration”.
  • Altered my TFS 2010 Build Definition and used the WebDeploy tool to create a deployment package and install it on the server.
  • Changed the “copy local” flag to true on the System.Web.Mvc assembly reference in my web project (as suggested in several pre-Razor articles about BIN deployment of ASP.NET MVC sites)
  • Ensured I was using a .NET 4 application pool.

Once all this was done and I browsed to the home page of the application, I started to get a series of errors about missing DLLs, starting with System.Web.Helpers. Additional missing assemblies included:

  • Microsoft.Web.Infrastructure
  • System.Web.Razor
  • System.Web.WebPages.Administration
  • System.Web.WebPages.Deployment
  • System.Web.WebPages.Razor

The solution compiled fine and ran okay on all the development machines. It turned out that these DLLs are needed for Razor based web pages and are a requirement over and above the standard ASP.NET MVC references.

My initial solution was to locate these assemblies and add references to them from the project with “copy local” as “true”. The assemblies are in the following folder on development machines:

C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies

However, it was, as I say, a series of errors as there were plenty of DLLs that needed to be added. On further searching it turned out that there is support in Visual Studio 2010 SP1 for including all of these dependent assemblies in the deployment without the need to add references to them.

AddDeployableDependenciesSimply right click on the web project in solution explorer and select “Add Deployable Dependencies” then select “ASP.NET Web Pages with Razor Syntax”. This adds the files to a “_bin_deployableAssemblies” folder in the web project. The contents of this folder are added to the web deployment package. Note that you can also check “ASP.NET MVC” so that you don’t have to remember to set “copy local” to “true” for the System.Web.Mvc assembly.

NOTE: You may have to remove the WebMatrix DLLs, added by this step, from the _bin_deployableAssemblies folder as they have the detrimental effect of redirecting the user to “Account/Logon” on every page request in some instances, regardless of the settings in your own web.config file. See this StackOverflow answer and this Microsoft Connect issue for more information.

The “Add Deployable Dependencies” is covered in more detail by Phil Haack in this blog post:

http://haacked.com/archive/2011/05/25/bin-deploying-asp-net-mvc-3.aspx

As many of the comments at the end of his blog point out, this does come across as a hack. One alternative would be to have some kind standalone installer for ASP.NET MVC 3 with Razor and to run this on the target server. Another alternative would be to add another option in the Web Platform Installer. Either of these would have worked great in my situation, but not when trying to deploy in a more locked down environment.

Advertisements
This entry was posted in Computers and Internet and tagged , , , , , . Bookmark the permalink.

2 Responses to Deploying ASP.NET MVC 3 Razor – Missing System.Web.Helpers (and others)

  1. Pingback: Publishing an MVC site to load balanced servers | danielksmith

  2. Bryce says:

    Thanks Josh! I know it’s 3 years after you posted this, but this was exactly my issue today and I was able to resolve it very quickly via your blog.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s