Monday, August 6, 2012

Bin deploy required dependencies for MVC 3 projects with Visual Studio 2010 SP1


If you have previously worked on ASP.NET MVC 2 projects and are making the move to MVC 3 you may have noticed that deploying projects to a server environment that doesn't have MVC installed is not as easy as it once was. Prior to MVC 3 we could simply set the "Copy Local" property to "True" on a couple of references that were already part of our project. With MVC 3 (and the Razor view engine) there are a set of dependencies that are not part of the default project setup and aren't required as a direct reference within the project. The full list of the required dependencies is:
  • Microsoft.Web.Infrastructure
  • System.Web.Helpers
  • System.Web.Mvc
  • System.Web.Razor
  • System.Web.WebPages
  • System.Web.WebPages.Deployment
  • System.Web.WebPages.Razor
Thankfully, Visual Studio 2010 Service Pack 1 provides an easy way to get these dependencies into your project without adding them as references and make them part of the bin dir on build.
Here is a look at our project structure (an MVC 3 web site) prior to adding the required dependencies:
alt text
If we bring up the context menu (right click) on our Website project we will see the option for Add Deployable Dependencies...
alt text
Click on that and we will get a dialog window with the option to select which MVC dependencies we want to include. Check both only the ASP.NET MVC dependency (see Phil Haack's comment down below for an explanation) and click OK.
alt text
And the results:
alt text
Holy cow that is a lot of files! A dir named _bin_deployableAssemblies gets added to the project with all the required dependency files. Visual Studio 2010 with Service Pack 1 will know to hit the dir with this name to add any required dependencies to the bin dir on build. That's it. Cake! Now we can go about our normal deployment business. If we use Web Deploy, well, everything is in our bin dir on the build action and the Web Deploy will deploy the bin dir so we are all set. If we have some other process to deploy, as long as we are including the full contents of the bin build dir then we are covered as well.
If you don't have Visual Studio 2010 Service Pack 1 installed you can check out Scott Hanselman's post BIN Deploying ASP.NET MVC 3 with Razor to a Windows Server without MVC installed.

No comments: