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

Posted on March 23rd, 2011

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.

Discussion

23 Mar, 2011 08:41 PM

woww. I didn't know that SP1 contains such a perfect feature. I have a blog post on this in my blog which can be found on http://tugberkugurlu.com/archive/deployment-of-asp-net-mvc-3-rc-2-application-on-a-shared-hosting-environment-without-begging-the-hosting-company and I gotta say that this is better.

Thanks !

Arroyocode
Arroyocode
24 Mar, 2011 06:41 AM

Excellent article yet again! I will continue to pay attention. Thanks for the write up/pics. Found this very useful.

24 Mar, 2011 08:42 AM

Really useful feature for those of us who use shared hosting.

Alexey Zimarev
24 Mar, 2011 10:44 AM

Cool, was copying these dependencies manually before :( Now the issue is solved indeed. Will give the link in my blog too.

24 Mar, 2011 04:22 PM

Glad I could share some helpful info!

Alexey:
The link to your blog doesn't appear to work (when clicking on your name in the comment). Can you add another comment with it in there so people can get to it?

24 Mar, 2011 10:23 PM

I just wanted to ask you that why did it include Nuget.Core.dll inside bindeployableAssemblies?

25 Mar, 2011 01:12 AM

Tugberk
Great question...I just noticed that on another project I ran this option on. It added that automatically. Maybe we need to inquire with the NuGet team about that. I will see if I can find the answer on it.

25 Mar, 2011 01:26 AM

I posted the question on the NuGet dll inclusion here:
I will update my post when I get an answer.

25 Mar, 2011 02:55 AM

You don't need to check ASP.NET Web Pages with Razor Syntax. That option is for the simple inline-pages framework. If you're just building an ASP.NET MVC application, only check the ASP.NET MVC option.

25 Mar, 2011 06:12 AM

Created a new MVC 3 project and checked only this:

One Check

...and ended up with this:

Result

Disco! Matches the bulleted list at the top of the article. Thanks Haacked.

25 Mar, 2011 06:28 AM

By the way, I updated the article to match this.

25 Mar, 2011 02:25 PM

Justin thanks for your concern and all of your effort. This makes it clear now.

Ron Veerman
Ron Veerman
18 Aug, 2011 01:01 PM

Just start using MVC3. I was not aware that the option was there already, thanks for clearing that out!

No new comments are allowed on this post.