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:
If we bring up the context menu (right click) on our Website project we will see the option for Add Deployable Dependencies...
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.
And the results:
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 new comments are allowed on this post.
Discussion
Tugberk Ugurlu
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
Excellent article yet again! I will continue to pay attention. Thanks for the write up/pics. Found this very useful.
Chris Poulter
Really useful feature for those of us who use shared hosting.
Cool, was copying these dependencies manually before :( Now the issue is solved indeed. Will give the link in my blog too.
Justin Schwartzenberger
Glad I could share some helpful info!
Tugberk Ugurlu
I just wanted to ask you that why did it include Nuget.Core.dll inside bindeployableAssemblies?
Justin Schwartzenberger
Justin Schwartzenberger
I posted the question on the NuGet dll inclusion here:
I will update my post when I get an answer.
Haacked
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.
Justin Schwartzenberger
Created a new MVC 3 project and checked only this:
...and ended up with this:
Disco! Matches the bulleted list at the top of the article. Thanks Haacked.
Justin Schwartzenberger
By the way, I updated the article to match this.
Tugberk Ugurlu
Justin thanks for your concern and all of your effort. This makes it clear now.
Ron Veerman
Just start using MVC3. I was not aware that the option was there already, thanks for clearing that out!