Bin Deploying ASP.NET MVC mvc, 0 comments suggest edit

With the release of ASP.NET MVC Beta, the assemblies distributed with ASP.NET MVC are automatically installed into the GAC.

  • System.Web.Mvc
  • System.Web.Routing
  • System.Web.Abstractions

While developing an application locally, this isn’t a problem. But when you are ready to deploy your application to a hosting provider, this might well be a problem if the hoster does not have the ASP.NET MVC assemblies installed in the GAC.

Fortunately, ASP.NET MVC is still bin-deployable. If your hosting provider has ASP.NET 3.5 SP1 installed, then you’ll only need to include the MVC DLL. If your hosting provider is still on ASP.NET 3.5, then you’ll need to deploy all three. It turns out that it’s really easy to do so.

Also, ASP.NET MVC runs in Medium Trust, so it should work with most hosting providers’ Medium Trust policies. It’s always possible that a hosting provider customizes their Medium Trust policy to be draconian.

What I like to do is use the Publish feature of Visual Studio to publish to a local directory and then upload the files to my hosting provider. If your hosting provider supports FTP, you can often skip this intermediate step and publish directly to the FTP site.

The first thing I do in preparation is to go to my MVC web application project and expand the References node in the project tree. Select the aforementioned three assemblies and in the Properties dialog, set Copy Local to True.


Now just right click on your application and select Publish.


This brings up the following Publish wizard.


Notice that in this example, I selected a local directory. When I hit Publish, all the files needed to deploy my app are available in the directory I chose, including the assemblies that were in the GAC.


Now I am ready to XCOPY the application to my host, but before I do that, I really should test the application as a bin deployed app to be on the safe side.

Ideally, I would deploy this to some staging server, or a virtual machine that does not have ASP.NET MVC installed. Otherwise, I’m forced to uninstall ASP.NET MVC on the current machine and then test the application.

You might be wondering, as I did, why I can’t just use gacutil to temporarily unregister the assembly, test the app, then use it again to register the assembly. Because it was installed using an MSI, Windows won’t let you unregister it. Here’s a command prompt window that shows what I got when I tried.


Notice that it says that “assembly is required by one or more applications”. In general, there shouldn’t be any difference between running your application with MVC gac’d and it ungac’d. But I wouldn’t trust me saying this, I’d test it out to be sure.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.



47 responses

  1. Avatar for Gabriel Bogea
    Gabriel Bogea November 3rd, 2008

    Thanks for the tip Phil. This is really useful since my hosting provider hasn't installed SP1 yet.

  2. Avatar for egor
    egor November 3rd, 2008

    What about deploying mvc application to host provider with medium trust? Is it going to work?

  3. Avatar for Simone Chiaretta
    Simone Chiaretta November 3rd, 2008

    Isn't the second last figure supposed to show all the dlls, including the MVC ones, and not just the mvcapplication.dll one?

  4. Avatar for Graeme
    Graeme November 3rd, 2008

    Hurrah, just what i was looking for. Now I can develop for ASP.NET MVC without having to get a dedicated server.

  5. Avatar for Salman
    Salman November 3rd, 2008

    25% of our problems are solved when we stay up to date on software patches ... (well that's what I read somewhere so it must be true!).

  6. Avatar for JH
    JH November 3rd, 2008

    I've always thought it's important for people to understand "How the Runtime Locates Assemblies"

  7. Avatar for JH
    JH November 3rd, 2008

    I find I keep coming back to the msdn article, "How the Runtime Locates Assemblies" to explain this.

  8. Avatar for haacked
    haacked November 3rd, 2008

    @egor yep, you can. I updated the post to mention that.
    @simone Yep, I'll fix it.

  9. Avatar for Lance Fisher
    Lance Fisher November 5th, 2008

    Thanks for the tips. I was just doing this stuff yesterday, and I was annoyed that I couldn't remove the dlls from the GAC. I didn't want to uninstall MVC because I didn't want to lose the project templates, etc.
    What I would like is to be able to test the app in IE6 from a VM, but since I had the dlls in the bin directory, I was getting some conflicts with the GAC when I ran the site in IIS.
    That "copy local" is a good tip. I had created a post-build step to copy the dlls, but I'm going to do it the right way instead now.

  10. Avatar for Boyan Kostadinov
    Boyan Kostadinov November 5th, 2008

    Where is the NAnt task to do all this with one step? I thought you were a NAnt fan :-)

  11. Avatar for codejudo
    codejudo November 7th, 2008

    you can always try to uninstall it from GAC using some brute force :-)

  12. Avatar for Dylan Beattie
    Dylan Beattie November 7th, 2008

    It's possible, with a little registry hacking, to remove System.Web.Mvc from the GAC after installing the beta, which lets you both test your bin deployment scenario locally, and run code that's using the preview releases alongside the beta if you need to. More details are here if you're interested. (Usual caveats about the dangers of registry hacking apply!)

  13. Avatar for codejudo
    codejudo November 7th, 2008

    you can always try to uninstall it from GAC using some brute force :-) more details

  14. Avatar for Rafael Soares
    Rafael Soares November 9th, 2008

    A little off topic:
    Could I do the same with Dynamic Data?

  15. Avatar for Jason
    Jason November 12th, 2008

    o , my God ! When i post all dll to my host server, but it is not work yet ! I can't find out any reason.

  16. Avatar for Wayne Austin
    Wayne Austin January 26th, 2009

    Great article, helped me alot with uploading my new MVC site.
    Thanks very much! :D

  17. Avatar for Sawka
    Sawka January 27th, 2009

    i have a problem with your solution about Grouping Controllers, simply ant override FindPartialView method in ViewEngineResult
    any ideas?

  18. Avatar for yohannes
    yohannes January 30th, 2009

    Awesome article. I finally published my MVC personal website.

  19. Avatar for Alex Scordellis
    Alex Scordellis February 1st, 2009

    I'm wondering why each version of MVC (Preview n, Beta, RC) has the same assembly version: As I understand it, this means that if either Beta or RC is in the GAC, no web app on that system can run the other version.
    The way it is now, either all projects on a server have to use the same GAC deployed version, or they all have to bin-deploy. If they were different versions, I think we'd be able to bind to specific versions for each app.

  20. Avatar for Chad Thiele
    Chad Thiele February 2nd, 2009

    My publish fails... doesn't give any good error message (it simply says "publish failed"). The build "builds" with no errors, just the publish fails.
    This is in Visual Studio 2008 (not express dev tools).
    Anyone else experience this? Any ideas?

  21. Avatar for Haakon
    Haakon March 2nd, 2009

    Hi, I have a problem with Windows Web Server 2008 and deploying an MVC project. I have a copy of the project from our previous server where everything worked fine, but no source code.
    The problem is that I am having trouble with the Futures assembly (RC1). It is impossible (?) to install on the server using gacutil.exe because it is not a strongly typed assembly. And even though the assembly is present in the projects bin folder (that was working fine on our 2000-server) it is not working now. I get "System.NullReferenceException: Object reference not set to an instance of an object" when browsing to the web site, and a pointer to the Html.MenuItem method as the source of the exception.
    What to do?

  22. Avatar for Dan Crowell
    Dan Crowell March 26th, 2009

    @RafaelSoares, you can bin deploy Dynamic Data. The list of dlls includes those applicable to Dynamic data such as: System.ComponentModel.DataAnnotations, System.Web.DynamicData, and System.Data.DataSetExtensions.

  23. Avatar for Clearly
    Clearly April 5th, 2009

    How do you perform the "Publish" from the command line so it can be built into continuous integration systems? aspnet_compiler doesn't seem to work anymore. Seriously, no one (or at least a million searches through Google) seems to know if or how this is possible.

  24. Avatar for Jeff Brown
    Jeff Brown February 13th, 2010

    so i get this error on my hosting server...
    Could not load all ISAPI filters for site 'mydomain.COM'. Therefore site startup aborted.
    it works locally.

  25. Avatar for Robert Steward
    Robert Steward April 27th, 2010

    Thanks Phil, This works great on M6.Net. I am moving from webforms after torturing myself with learning PHP, ugh. Now on to MVC.
    Thanks again, you've made my day work alot faster.

  26. Avatar for Chicago mover
    Chicago mover August 11th, 2010

    That really helps me in publishing my MVC site.

  27. Avatar for L6zi75
    L6zi75 August 30th, 2010

    How do you perform the "Publish" from the command line so it can be built into continuous integration systems? how to jump higher kettlebell exercises aspnet_compiler doesn't seem to work anymore. Seriously, no one (or at least a million searches through Google) seems to know if or how this is possible.

  28. Avatar for Clifford P. Santos
    Clifford P. Santos September 1st, 2010

    Nice~! Thanks~! Solved My Problem~! ^_^

  29. Avatar for Paul Jones
    Paul Jones September 7th, 2010

    Yeah, MVC is the way. Checkout RoR. kettlebell exercises

  30. Avatar for Slava
    Slava November 8th, 2010

    Nice post, now I know ASP.NET MVC deployment kung fu.

  31. Avatar for Jack
    Jack December 30th, 2010

    i generate a sample MVC application thru the VS Express 2010 without changing any code, it works fine in my local PC. When i try to upload the project to hosting server(production server) for testing, i got an error:

    Could not load type 'System.Web.Mvc.UrlParameter' from assembly 'System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
    Using 4, IIS 7.0
    With Bin deploy also not working. :(

  32. Avatar for Arturito.NET
    Arturito.NET January 20th, 2011

    Deploying MVC2:

  33. Avatar for Jekke
    Jekke February 10th, 2011

    This works well with MVC 2. With MVC 3, you need to add a half-dozen more files to your "copy local" list including some that aren't in the references for the default project. If you walk through the "file not found" exceptions, it's pretty straightforward which ones you need.

  34. Avatar for ahmad
    ahmad March 7th, 2011

    i not understand byyyyyyyyyye

  35. Avatar for Victor Juri
    Victor Juri March 29th, 2011

    I am hosting with Godaddy and this worked great for me. I love MVC, find it very intuitive. Appreciate all your work on it, videos, tutorials, post like these.
    Thanks Phil

  36. Avatar for Chaaya
    Chaaya April 3rd, 2011

    Thanks a Million, Saved a lot of my time.

  37. Avatar for Azure Diagnostics
    Azure Diagnostics April 20th, 2011

    Thanks so much, that made all the difference. I did find that I had to publish to GoDaddy using FTP and it did not work when I first published to the hard drive and manually ftp'd. I am not sure what the difference was though...

  38. Avatar for Mihai
    Mihai June 1st, 2011

    worked for MVC3

  39. Avatar for Sudipta Manna
    Sudipta Manna September 12th, 2011

    Sir, I am very new to MVC application. I ve build a small, MVC project and have bought domain. BUT i am getting error for uploding the file..and it creating problem in web config saying

    Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
    Source Error:

    Line 20: </assemblies>
    Line 21: </compilation>
    Line 22: <authentication mode="Forms">
    Line 23: <forms loginUrl="~/Account/LogOn" timeout="2880" />
    Line 24: </authentication>

    Source File: D:\inetpub\vhosts\\httpdocs\medclinapplication\medclinapplication\web.config Line: 22
    can any 1 help me???

  40. Avatar for kenanbek
    kenanbek September 25th, 2011
    also this may be useful

  41. Avatar for Doc
    Doc November 4th, 2011

    Thanks very much!!!

  42. Avatar for Mikhail Tsennykh
    Mikhail Tsennykh February 20th, 2012

    Thanks Phil!!! I fixed my MVC3 deployment issue!
    3 years after you made this post, and it is still helping people!

  43. Avatar for Carlos Hidalgo
    Carlos Hidalgo April 26th, 2012

    You need to install these software requirements:
    AspNetMVC3ToolsUpdateSetup & Application Request Routing

  44. Avatar for Jason Watmore
    Jason Watmore May 14th, 2012

    Thanks very much!
    For my MVC3 project I had to add references to these assemblies:
    - System.Web.WebPages.Razor
    - System.Web.Razor
    - System.Web.WebPages.Deployment
    And set Copy Local to True for these assemblies:
    - System.Web.Helpers
    - System.Web.Mvc
    - System.Web.WebPages
    - System.Web.WebPages.Razor
    - System.Web.Razor
    - System.Web.WebPages.Deployment

  45. Avatar for Jagz W
    Jagz W March 15th, 2013

    thanks for help.

    It works for me

  46. Avatar for Don
    Don August 3rd, 2013

    Excellent, thanks a lot, works great.

  47. Avatar for Cuneyt
    Cuneyt December 8th, 2015

    Good one. Never gets old!