Visual Studio compile is not copying dependent DLLs to the bin folder


This is just a quick note about a problem I encountered while creating plugins.

In this case, I am not creating NuGet packages for my plugins. The idea here is for each plugin to create a folder with all its required content. That folder would be copied to another location for the client app to consume. This is a model I see often used for games and is the model I am trying for here. I mention this because many of the posts I saw while trying to fix my issue included getting sidetracked by the fact that NuGet was involved.

So, what I am trying to accomplish is to have the Plugin_A project compile into the /bin/Release/net5.0/ folder. The contents of that folder would become my /Plugin_A folder. Now /Plugin_A can be copied into my client application’s /PutPluginsHere folder where it can be found and utilized.

And now, my problem…

When I compiled my Plugin_A project using Visual Studio 2019, I found that it did put the plugin’s DLL into the /bin/Debug/net5.0/ and /bin/Release/net5.0/ folders. But the plugin references other DLLs, like HtmlAgilityPack.dll and System.ServiceModel.Syndication.dll, and these were not in the /bin folders. That would mean that when I copied the /Plugin_A folder to /PutPluginsHere, the client application would find Plugin_A.dll, but could not load it because it would be missing dependencies.

I searched the net to try and find out how to ensure that HtmlAgilityPack.dll and System.ServiceModel.Syndication.dll were copied to the /bin folders, but the majority of the answers ended up being workarounds like using xcopy to force the missing DLLs to be copied and other such manual methods.

I finally did find the solution. It involves adding one line to the Plugin_A.cproj file:

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

Adding that line inside the <PropertyGroup> tag solved the issue. The dependent DLLs are now copied to the /bin folders. You can read what Microsoft has to say about it here.

One thought on “Visual Studio compile is not copying dependent DLLs to the bin folder”

  1. Thanks – this was mostly helpful in my plug-in project. One part of that doesn’t work for me are the references of the references. So, if I have included in my .NET 6 project Microsoft.Extensions.Configuration and Microsoft.Extensions.Configuration.Json, I found that only the first one (Configuration) would copy. The other one (Json) did not. When I’d use the plug-in on my local computer, it worked great, but the same code to a deployed server couldn’t find the reference and would get MissingMethod errors. Manually copying the missing DLL to the server fixed this.
    Ever experience this? And if so, how did you fix it?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s