Bin Deploying ASP.NET MVC 3

asp.net, asp.net mvc, code 0 comments suggest edit

When you build an ASP.NET MVC 3 application and are ready to deploy it to your hosting provider, there are a set of assemblies you’ll need to include with your application for it to run properly, unless they are already installed in the Global Assembly Cache (GAC) on the server.

In previous versions of ASP.NET MVC, this set of assemblies was rather small. In fact, it was only one assembly, System.Web.Mvc.dll,though in the case of ASP.NET MVC 1.0, if you didn’t have SP1 of .NET 3.5 installed, you would have also needed to deploy System.Web.Abstractions.dll and System.Web.Routing.dll.

But ASP.NET MVC 3 makes use of technology shared with the new ASP.NET Web Pages product such as Razor. If you’re not familiar with ASP.NET Web Pages and how it fits in with Web Matrix and ASP.NET MVC, read David Ebbo’s blog post, How WebMatrix, Razor, ASP.NET Web Pages, and MVC fit together.

If your server doesn’t have ASP.NET MVC 3 installed, you’ll need to make sure the following set of assemblies are deployed in the bin folder of your web application:

  • Microsoft.Web.Infrastructure.dll
  • System.Web.Helpers.dll
  • System.Web.Mvc.dll
  • System.Web.Razor.dll
  • System.Web.WebPages.Deployment.dll
  • System.Web.WebPages.dll
  • System.Web.WebPages.Razor.dll

In this case, it’s not as simple as looking at your list of assembly references and setting Copy Local to True as I’ve instructed in the past.

As you can see in the following screenshot, not every assembly is referenced. Not all of these assemblies are meant to be programmed against so it’s not necessary to actually reference**each of these assemblies. They just need to be available on the machine either from the GAC or in the bin folder.

referenced-assemblies

But the Visual Web Developer team has you covered. They added a feature specifically for adding these deployable assemblies. Right click on the project and select Add Deployable Assemblies and you’ll see the following dialog.

add-deployable-assemblies

When building an ASP.NET MVC application, you only need to check the first option. Ignore the fact that the second one says “Razor”. “ASP.NET Web Pages with Razor syntax”was the official full name of the product we simply call ASP.NET Web Pages now. Yeah, it’s confusing.

Note that there’s also an option for SQL Server Compact, but that’s not strictly necessary if you’ve installed SQL Server Compact via NuGet.

So what happens when you click “OK”?

bin-deployable-assemlies

A special folder named _bin_deployableAssemblies is created and the necessary assemblies are copied into this folder. Web projects have a built in build task that copies any assemblies in this folder into the bin folder when the project is compiled.

Note that this dialog did not add any assembly references to these assemblies. That ensures that the types in these assemblies don’t pollute Intellisense, while still being available to your deployed application. If you actually need to use a type in one of these assemblies, you’re free to reference them.

So here’s the kicker. If you’re building a web application, and you need an assembly deployed but don’t want it referenced and don’t want it checked into the bin directory, you can simply add this folder yourself and put your own assemblies in here.

If you’ve ever run into a problem where an ASP.NET MVC site you developed locally doesn’t work when you deploy it, this dialog may be just the ticket to fix it.

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

Comments

avatar

43 responses

  1. Avatar for Brad
    Brad May 25th, 2011

    Is it possible to change the name of the _bin_deployableAssemblies folder in a project?

  2. Avatar for Stefan Kip
    Stefan Kip May 25th, 2011

    I just tried this with a ASP.NET 4.0 Web Project:
    - Added folder called "_bin_deployableAssemblies"
    - Added two assemblies to the folder
    - Cleared the bin folder
    - Built with VS2010 SP1
    It works great! Last weeks I've really been looking for something like this, thanks!

  3. Avatar for Wimp
    Wimp May 25th, 2011

    You just save my day. I've been trying to do this on a client this-have-to-be-online-today rush on a non mvc3 hosting. really thx a lot :D

  4. Avatar for Stefan Kip
    Stefan Kip May 25th, 2011

    Oh Phil; just a question. We're using Subversion (*sigh* I know) and I've added "_bin_deployableAssemblies" to svn, but the "bin" folder is on the ignore list.
    Though "_bin_deployableAssemblies" has a ".svn" folder inside, which gets copied to the bin folder as well, while it shouldn't be.
    Any tip/trick/fix for this?

  5. Avatar for Stefan Kip
    Stefan Kip May 25th, 2011

    Well I solved my own question by using this as post-build event:
    rmdir "$(TargetDir).svn" /Q/S
    Problem is, when you publish the web application, the .svn folder will still be included in the bin folder and I really can't find a solution for this issue.

  6. Avatar for Stefan Kip
    Stefan Kip May 25th, 2011

    Lol and again, I solved my own problem with this post:
    stackoverflow.com/...
    Just add this to the .csproj file underneath the last <import /> line:
    <Target Name="_CopyBinDeployableAssemblies" Condition="Exists('$(MSBuildProjectDirectory)\_bin_deployableAssemblies')">
    <CreateItem Include="$(MSBuildProjectDirectory)\_bin_deployableAssemblies\**\*.*" Condition="Exists('$(MSBuildProjectDirectory)\_bin_deployableAssemblies')" Exclude="$(MSBuildProjectDirectory)\_bin_deployableAssemblies\.svn\**\*">
    <Output ItemName="_binDeployableAssemblies" TaskParameter="Include" />
    </CreateItem>
    <Copy SourceFiles="@(_binDeployableAssemblies)" DestinationFolder="$(OutDir)\%(RecursiveDir)" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
    </Target>

  7. Avatar for Justin
    Justin May 25th, 2011

    Thanks for the tips Phil. I have to do this regularly for components that are not installed with y provider. It also insulates the application against upgrades to the server allowing me to upgrade an application when I want to not when my provider updates a library and forgets to tell everyone.

  8. Avatar for kamranayub
    kamranayub May 25th, 2011

    Where are things like this documented? Are there a lot of surprise conventions like this we don't know about? It'd be nice to know considering this feature is pretty nice and would have been great to know about.

  9. Avatar for Terry Brown
    Terry Brown May 25th, 2011

    it'd be really nice if this followed the same convention as nuget and used the packages folder (or at least allowed you to choose so that you could elect to follow that convention).
    Great feature, though I'd rather not mess up my web project with the dependencies if I could store them elsewhere.

  10. Avatar for dotnetchris
    dotnetchris May 25th, 2011

    @Terry Brown does that really buy you anything? I personally see the bin_deployable folder as just an ancillary bin folder that has stuff my project needs at runtime but that I don't really care about.
    I wouldn't mix those files into my packages since those are things I actually specifically care about.

  11. Avatar for Harvey Meeker
    Harvey Meeker May 26th, 2011

    Sounds good. I was running into this problem when deploying my code out to a host and had to go searching for the various missing DLLs.

  12. Avatar for Nacho
    Nacho May 26th, 2011

    Anyone have some tips on deploying to appharbor with sql ce?. I have checked sql ce to bin deployable dependencies but i still cant get it to work... layout is shown but content just displays error message... the app dashboard shows no errors in the error log.

  13. Avatar for Aaron
    Aaron May 26th, 2011

    Phil, I do appreciate the explanation of all what is going on here, because its helpful for those of us that use MVC, but IMO Microsoft needs to be making an ever increasing effort to reduce the complexity of toolsets, especially not introducing new features that require you to remember "another thing". IMO existing features need to be refactored rather than compensating ones added.
    I use a lot of MS tools, but I have had all I will ever want of compiling mental matrices of all the possible ways to get something to work in x version of a particular MS product.

  14. Avatar for James Culbertson
    James Culbertson May 26th, 2011

    @Nacho,
    AppHarbor doesn't support SQL CE, due to the way they do the hosting it doesn't support that type of database access. They do provide a SQL Server option though and it's relatively easy to migrate your SQL CE to SQL Server.

  15. Avatar for Adrian Lanning
    Adrian Lanning May 26th, 2011

    Thanks Phil. I don't know all of the intricacies involved but have you considered making this on-by-default? In terms of impact it seems like the following breakdown would apply:
    * Need fix, not on-by-default = broken app and a potentially bad experience with MVC3
    * Need fix, on-by-default = works
    * Don't need fix, not on-by-default = no impact
    * Don't need fix, on-by-default = some wasted disk space (DLL's already in GAC)

  16. Avatar for Steve French
    Steve French May 26th, 2011

    Will this work if the web server only has the .net framework 3.5 installed?

  17. Avatar for Christian Crowhurst
    Christian Crowhurst May 27th, 2011

    Excellent idea but has limitations which for me meant that I didn't use it.
    I store dll dependencies within MyApp\lib folder whereas my source in MyApp\src.
    I tried to be clever and manually add dll's into this new special folder (_bin_deployableAssemblies), using "Add As Link", and selecting the dll from MyApp\lib folder. Problem is, the dll added to _bin_deployableAssemblies in this way never gets copied by VS2010 into the bin directory when doing a compile.
    So for me, I'm reluctantly sticking with referencing all the dll's from my csproj file, and setting Copy Local to True :-(
    Christian

  18. Avatar for Nacho
    Nacho May 27th, 2011

    @James,
    are you sure about that? I have looked up some info on this and I apparently it is supported.
    support.appharbor.com/...
    support.appharbor.com/.../519-sql-server-compact
    stackoverflow.com/...

  19. Avatar for Keith Dahlby
    Keith Dahlby May 27th, 2011

    Since bin deployment is important enough to justify special tooling in VS, could you explain the decision process that pushed these assemblies into the GAC in the first place?

  20. Avatar for tugberk
    tugberk May 28th, 2011

    @Kamran
    this is a known feature for long time and has been blogged before.
    www.hanselman.com/...
    now it is built into GUI.

  21. Avatar for haacked
    haacked May 29th, 2011

    @Christian, why not add a pre-build step to copy the DLLs to this folder? ;)
    @Keith I think it's old school policies not keeping up with what customers really want. We can't service assemblies that aren't in the GAC. However, my hope is we fix that problem, rather than continuing to put things it the GAC for no good reason.

  22. Avatar for Konstantin Tarkus
    Konstantin Tarkus June 2nd, 2011

    Looks like a workaround.. Ok, good. But what about Entity Framework 4.1? Just coping it's .dll into bin folder won't help during deployment on a server where EF 4.1 wasn't installed.

  23. Avatar for Brett Slaski
    Brett Slaski June 16th, 2011

    I figure the _bin_deployableAssemblies should be ignored by source control. What is your opinion on this?

  24. Avatar for haacked
    haacked June 18th, 2011

    @Brett Why? If you ignore them, then how does the next person get those assemblies into their bin directory when building?

  25. Avatar for haacked
    haacked June 18th, 2011

    @Konstantin EF 4.1 works for me bin deployed. What problems are you running into?

  26. Avatar for C.Hazelton
    C.Hazelton July 30th, 2011

    Phil this got me in the right direction but there were a couple extra references that were needed for GoDaddy shared hosting until they update their shared hosting environment. They are listed here.

  27. Avatar for Paul
    Paul August 12th, 2011

    My hoster does not support Full Trust. Do you need Full Trust to use these bin deployed dll's. I am unclear as to what exactly I will not be able to do without full trust.

  28. Avatar for Edgar Rojas
    Edgar Rojas September 14th, 2011

    I did all of this but my host provider (aplusnet) they ask me for a index or default page... what I can do?

  29. Avatar for Saeed Neamati
    Saeed Neamati November 6th, 2011

    Haccked, I was trying to upload a new website, which was written using ASP.NET MVC 3, and guess what, the shared hosting didn't provide the installation for me. So, your post was a survivor for me. Many thanks for article. I simply copied the DLL files of MVC3 to the bin folder of the uploaded application, and everything now works like a charm.

  30. Avatar for High-Flying.co.uk
    High-Flying.co.uk November 24th, 2011

    Thanks! Just what I needed to know for deploying to 3rd party servers which don't have MVC 3 installed. Maybe I'll get your book

  31. Avatar for Melissa
    Melissa January 24th, 2012

    Here is a brief explanation as well for deploying ASP.NET MVC3 application on server: blog.teamgrowth.net/...
    Cheers!! :)

  32. Avatar for Jojy Alex
    Jojy Alex February 23rd, 2012

    What is this???

  33. Avatar for Tomi
    Tomi April 3rd, 2012

    Hey we are using TFS and one of us add deployable dependencies on his version which didnt work correctly when we want to delete it and add it again on version which work than opened a window with error: That some dll which we want to add already exist or we do not have permission for access. How can we delete and add new deployable dependencies?

  34. Avatar for Misi Moisei
    Misi Moisei June 1st, 2012

    Did anything changed/was added for ASP.NET MVC 4 ?

  35. Avatar for Muru
    Muru July 5th, 2012

    Is that possible now to deploy MVC 4 , .Net 4.0 application without any issues ? Which IIS Version is the required one to use . Thanks for the help.

  36. Avatar for Edi
    Edi August 20th, 2012

    Hi. The Add Deployable Dependencies does not exists in VS2012. I saw MS answers on connect.microsoft.com/... which says VS2012 will do it automatically. But when I publish the MVC3 site (upgrated from VS2010), there are no MVC3 dlls copied to bin.

  37. Avatar for haacked
    haacked August 20th, 2012

    Hi Edi,
    I'm looking into it. There should be NuGet packages for MVC 3 by now, but I haven't tried it myself.

  38. Avatar for haacked
    haacked August 20th, 2012

    Hi Edi,
    Use the Package Manager Console and run the following command:

    Install-Package Microsoft.AspNet.Mvc -Version 3.0.20105.1


    That should reference all the assemblies in a manner that will make it bin deployable.

  39. Avatar for $48332041
    $48332041 September 20th, 2012

    Worked in seconds, thank you, Phil!

  40. Avatar for Stefan Kip
    Stefan Kip September 20th, 2012

    How about VS2012 and external assemblies?
    stackoverflow.com/...

  41. Avatar for Ygor Thomaz
    Ygor Thomaz September 22nd, 2012

    Thanks for the TIP!! TFTT

  42. Avatar for Mohmmad Shahnawaz
    Mohmmad Shahnawaz May 29th, 2013

    no never...

  43. Avatar for Jon
    Jon November 2nd, 2014

    How did you solve this problem?