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

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.

Published on Apr 14, 2019

Tags: dll | ASP.NET MVC and Web API Tutorial | c#

Related Posts

Did you enjoy this article? If you did here are some more articles that I thought you will enjoy as they are very similar to the article that you just finished reading.

Tutorials

Learn how to code in HTML, CSS, JavaScript, Python, Ruby, PHP, Java, C#, SQL, and more.

No matter the programming language you're looking to learn, I've hopefully compiled an incredible set of tutorials for you to learn; whether you are beginner or an expert, there is something for everyone to learn. Each topic I go in-depth and provide many examples throughout. I can't wait for you to dig in and improve your skillset with any of the tutorials below.