Bin Deploying ASP.NET MVC 3

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.

What others have said

Requesting Gravatar... Brad May 25, 2011 12:55 PM
# re: Bin Deploying ASP.NET MVC 3
Is it possible to change the name of the _bin_deployableAssemblies folder in a project?
Requesting Gravatar... Stefan Kip May 25, 2011 4:35 PM
# re: Bin Deploying ASP.NET MVC 3
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!
Requesting Gravatar... Wimp May 25, 2011 5:06 PM
# re: Bin Deploying ASP.NET MVC 3
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
Requesting Gravatar... Stefan Kip May 25, 2011 5:17 PM
# re: Bin Deploying ASP.NET MVC 3
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?
Requesting Gravatar... Stefan Kip May 25, 2011 7:15 PM
# re: Bin Deploying ASP.NET MVC 3
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.
Requesting Gravatar... Stefan Kip May 25, 2011 8:21 PM
# re: Bin Deploying ASP.NET MVC 3
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>
Requesting Gravatar... Justin May 25, 2011 8:42 PM
# re: Bin Deploying ASP.NET MVC 3
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.
Requesting Gravatar... Kamran May 25, 2011 8:48 PM
# re: Bin Deploying ASP.NET MVC 3
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.
Requesting Gravatar... Terry Brown May 25, 2011 9:10 PM
# re: Bin Deploying ASP.NET MVC 3
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.
Requesting Gravatar... Chris Marisic May 25, 2011 11:00 PM
# re: Bin Deploying ASP.NET MVC 3
@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.
Requesting Gravatar... Harvey Meeker May 26, 2011 4:20 AM
# re: Bin Deploying ASP.NET MVC 3
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.
Requesting Gravatar... Nacho May 26, 2011 7:22 AM
# re: Bin Deploying ASP.NET MVC 3
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.
Requesting Gravatar... Aaron May 26, 2011 9:15 AM
# re: Bin Deploying ASP.NET MVC 3
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.
Requesting Gravatar... James Culbertson May 26, 2011 10:22 AM
# re: Bin Deploying ASP.NET MVC 3
@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.
Requesting Gravatar... Adrian Lanning May 26, 2011 10:46 AM
# re: Bin Deploying ASP.NET MVC 3
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)
Requesting Gravatar... Steve French May 26, 2011 11:15 AM
# re: Bin Deploying ASP.NET MVC 3
Will this work if the web server only has the .net framework 3.5 installed?
Requesting Gravatar... Christian Crowhurst May 27, 2011 3:50 AM
# re: Bin Deploying ASP.NET MVC 3
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
Requesting Gravatar... Nacho May 27, 2011 4:22 AM
# re: Bin Deploying ASP.NET MVC 3
@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/...
Requesting Gravatar... Keith Dahlby May 27, 2011 10:14 PM
# re: Bin Deploying ASP.NET MVC 3
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?
Requesting Gravatar... tugberk May 28, 2011 5:18 AM
# re: Bin Deploying ASP.NET MVC 3
@Kamran

this is a known feature for long time and has been blogged before.

www.hanselman.com/...

now it is built into GUI.
Requesting Gravatar... haacked May 29, 2011 1:39 PM
# re: Bin Deploying ASP.NET MVC 3
@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.
Requesting Gravatar... Konstantin Tarkus Jun 02, 2011 3:47 AM
# re: Bin Deploying ASP.NET MVC 3
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.
Requesting Gravatar... Brett Slaski Jun 16, 2011 1:06 PM
# re: Bin Deploying ASP.NET MVC 3
I figure the _bin_deployableAssemblies should be ignored by source control. What is your opinion on this?
Requesting Gravatar... haacked Jun 18, 2011 5:05 AM
# re: Bin Deploying ASP.NET MVC 3
@Brett Why? If you ignore them, then how does the next person get those assemblies into their bin directory when building?
Requesting Gravatar... haacked Jun 18, 2011 5:06 AM
# re: Bin Deploying ASP.NET MVC 3
@Konstantin EF 4.1 works for me bin deployed. What problems are you running into?
Requesting Gravatar... C.Hazelton Jul 31, 2011 1:02 AM
# re: Bin Deploying ASP.NET MVC 3
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.
Requesting Gravatar... Paul Aug 12, 2011 11:54 AM
# re: Bin Deploying ASP.NET MVC 3
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.
Requesting Gravatar... Edgar Rojas Sep 14, 2011 11:42 AM
# re: Bin Deploying ASP.NET MVC 3
I did all of this but my host provider (aplusnet) they ask me for a index or default page... what I can do?
Requesting Gravatar... Saeed Neamati Nov 06, 2011 7:34 PM
# Great Help
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.
Requesting Gravatar... High-Flying.co.uk Nov 24, 2011 7:48 AM
# re: Bin Deploying ASP.NET MVC 3
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
Requesting Gravatar... Melissa Jan 24, 2012 11:01 AM
# re: Bin Deploying ASP.NET MVC 3
Here is a brief explanation as well for deploying ASP.NET MVC3 application on server: blog.teamgrowth.net/...

Cheers!! :)
Requesting Gravatar... Jojy Alex Feb 23, 2012 9:40 AM
# re: Bin Deploying ASP.NET MVC 3
What is this???
Requesting Gravatar... Tomi Apr 03, 2012 1:08 PM
# re: Bin Deploying ASP.NET MVC 3
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?

What do you have to say?

(will show your gravatar)
Please add 4 and 2 and type the answer here: