Since ASP.NET MVC 3 was released last week, I've had several folks ask me how they can deploy their MVC 3 apps to a web hosting service. They asked because when they attempted to upload their app's files, they saw this error (or one similar to it):
What's the Problem?
When you install MVC 3 on your local machine, a number of assemblies are registered in the GAC. MVC 3 needs these assemblies. Unless your web hosting service has installed MVC 3 on their servers (and many haven't, yet), those assemblies won't be there, and you'll see an error similar to the one above.
What's the Solution?
As with previous versions of MVC, we suggest you solve this with what we call "\bin deployment." Bin Deployment is just a fancy term that means "include the MVC assembly (and its dependencies) in your web application's /bin folder." It's not hard to prepare your project for Bin Deployment, but there are a few more assemblies involved compared to MVC 2. I'll show you what you need to do, step by step.
Step 1: Add Explicit References for MVC and Its Dependencies
Your MVC app's project probably won't have references to all of the assemblies it needs, because they're in the GAC. So you need to add them. Here is the list (they'll all be available in the .NET tab of the Add Reference dialog):
- Microsoft.Web.Infrastructure
- System.Web.Helpers
- System.Web.Mvc
- System.Web.Razor
- System.Web.WebPages
- System.Web.WebPages.Deployment
- System.Web.WebPages.Razor
Step 2: Change Each Reference's Copy Local Property to True
After adding the references, you need to set the Copy Local property for each of the references you just added to True, as pictured below.
Step 3: Re-Build and Deploy as You Normally Would
Now, when you build your app, the MVC assembly and its dependencies will be copied to the /bin directory, allowing you to deploy as you normally would.
I hope this helps.
If you have any questions or concerns about this 'blog post, or in general, please send an email to drewmi at microsoft dot com. I'm also on Twitter at http://twitter.com/anglicangeek.