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.
Simply 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.
2 replies on “Deploying ASP.NET MVC 3 Razor – Missing System.Web.Helpers (and others)”
[…] put this in the GAC but then I thought this could be due to MVC not being installed on the server. I found this post by Josh Gallagher, which details quite nicely how to ‘Add Deployable Depende…. Doing this meant my site was up and running and I didn’t need to re-start live servers […]
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.