Dependent DLL is not getting copied to the build output folder in Visual Studio

D

I was struggling the other day where one of my NuGet packages DLL that was installed in a separate MVC project was not being copied to my bin directory. I have discovered two potentially reasons why this was occurring. Read on for two different potential solutions.

Let’s start with a bit of background, this problem occurred for me when I was trying to include two different versions of the same DLL. The solution to this problem is the second solution as I believe the first problem is more likely.

Add the NuGet reference to the main project

Sometimes a NuGet package that is added to one project may not get copied to the bin directory of your main application, be it a class library or MVC project.

The simple solution I encountered was to add the NuGet package to my MVC project. In one particular case this solved my problem. In another it did not, see solution 2 that solved my other problem.

Duplicate assembly names with different versions

A common problem that occurs is when you install multiple NuGet packages that contain dependencies to other NuGet packages. There are a lot of NuGet packages that depend on Json.Net and of course they often have depend on different versions of the package.

When Visual Studio is compiling your project and you have two different references to the small DLL Microsoft does not copy either DLL to the bin directory.

The resolution to this problem is to amalgamate the duplicate assemblies to the same version.

If you were stuck like me and how to maintain the two different versions, check out my solution to two different versions of the same DLL.

About the author

By Jamie

My Books