# Specify dll location using plugin in cooked project?

**URL:** <https://forums.unrealengine.com/t/specify-dll-location-using-plugin-in-cooked-project/436693>\
**Category:** Plugins\
**Tags:** dll, unreal-engine, Packaging, Plugins, question\
**Created:** [October 30, 2018, 9:50am UTC](https://forums.unrealengine.com/t/specify-dll-location-using-plugin-in-cooked-project/436693 "2018-10-30T09:50:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_e1d5ba97](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e1d5ba97](https://forums.unrealengine.com/u/anonymous_user_e1d5ba97)\
**Post date:** [October 30, 2018, 9:50am UTC](https://forums.unrealengine.com/t/specify-dll-location-using-plugin-in-cooked-project/436693/1 "2018-10-30T09:50:53Z")

</div>

I have made a plugin to interact with some exotic hardware that we use internally. This plugin depends on a third party DLL file. Lets call this file `my_exotic_hardware.dll`. I have successfully made the plugin work in both the editor and in runtime. My only problem right now is when I package this project the plugin DLL end up in the wrong folder.

Right now the DLL file end up in the folder:

`Engine\Plugins\Runtime\MyExoticHardwarePlugin\Source\ThirdParty\ExoticHardware\64\lib\my_exotic_hardware.dll`

So I every developer is forced to manually move the file from this folder to the same directory as the game executable, i.e. the root of the above path.

How do I adapt my build script so that the DLL file gets copied into the correct library during packaging? I would like to avoid the manual copy.

---

<div class="post-metadata">

**Author:** ![Jay2645](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jay2645](https://forums.unrealengine.com/u/Jay2645)\
**Post date:** [January 25, 2019, 10:44am UTC](https://forums.unrealengine.com/t/specify-dll-location-using-plugin-in-cooked-project/436693/2 "2019-01-25T10:44:36Z")

</div>

This is a few months old, but since nobody has answered you, there are 2 steps:

1. Copy the .dll file into the Binaries folder
2. Adding the _copied_ DLL to the runtime dependencies.

Everything below goes into your .build.cs file.

First, a couple helper functions to copy the DLL:

```
public string GetUProjectPath()
{
	return Path.Combine(ModuleDirectory, "../../../..");
}

private string CopyToProjectBinaries(string Filepath, ReadOnlyTargetRules Target)
{
	string BinariesDir = Path.Combine(GetUProjectPath(), "Binaries", Target.Platform.ToString());
	string Filename = Path.GetFileName(Filepath);

	//convert relative path 
	string FullBinariesDir = Path.GetFullPath(BinariesDir);

	if (!Directory.Exists(FullBinariesDir))
	{
		Directory.CreateDirectory(FullBinariesDir);
	}

	string FullExistingPath = Path.Combine(FullBinariesDir, Filename);
	bool ValidFile = false;

	//File exists, check if they're the same
	if (File.Exists(FullExistingPath))
	{
		ValidFile = true;
	}

	//No valid existing file found, copy new dll
	if (!ValidFile)
	{
		File.Copy(Filepath, Path.Combine(FullBinariesDir, Filename), true);
	}
	return FullExistingPath;
}

```

Next, make the DLL a dependency so it gets copied automatically:

```
string pluginDLLPath = PATH_TO_YOUR_DLL_FILE;
string binariesPath = CopyToProjectBinaries(pluginDLLPath, Target);
System.Console.WriteLine("Using Python DLL: " + binariesPath);
RuntimeDependencies.Add(binariesPath);
```

---

<div class="post-metadata">

**Author:** ![L05](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@L05](https://forums.unrealengine.com/u/L05)\
**Post date:** [September 22, 2019, 12:15am UTC](https://forums.unrealengine.com/t/specify-dll-location-using-plugin-in-cooked-project/436693/3 "2019-09-22T00:15:44Z")

</div>

This is the only solution I’ve found thus far that properly copies DLL files for third party plugins to the packaged project’s _Binaries_ folder. Thanks!

---

<div class="post-metadata">

**Author:** ![ColdBeamGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/coldbeamgames/32/782884_2.png) [@ColdBeamGames](https://forums.unrealengine.com/u/ColdBeamGames)\
**Post date:** [June 29, 2020, 2:19pm UTC](https://forums.unrealengine.com/t/specify-dll-location-using-plugin-in-cooked-project/436693/4 "2020-06-29T14:19:48Z")

</div>

Thanks for posting this, it really helped me out.

---

<div class="post-metadata">

**Author:** ![goodtrailer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@goodtrailer](https://forums.unrealengine.com/u/goodtrailer)\
**Post date:** [July 14, 2020, 1:19am UTC](https://forums.unrealengine.com/t/specify-dll-location-using-plugin-in-cooked-project/436693/5 "2020-07-14T01:19:15Z")

</div>

This is super old, I know, but there’s a much, much easier way, so I am going to leave this answer for anyone else looking for an answer in the future.

* * *

`RuntimeDepenencies.Add` actually has a **2 argument overload:** ([read more here](https://docs.unrealengine.com/en-US/Programming/BuildTools/UnrealBuildTool/ThirdPartyLibraries/#runtimedependencies))

1. Target destination for the DLL (in this case, the Binaries folder)
2. Source location for the DLL (which is the argument you would normally pass into RuntimeDependencies.Add)

Additionally, **UBT provides very useful string variables that point to specific directories** ([read more here](https://docs.unrealengine.com/en-US/Programming/BuildTools/UnrealBuildTool/ThirdPartyLibraries/#runtimedependencies)). In this case, what you want are `"$(BinaryOutputDir)"` and `"$(ModuleDir)"`. `"$(PluginDir)"` can also be used instead of `"$(ModuleDir)"`, and it points to the directory that the .uplugin is in, instead of where the .build.cs is (in my case, they’re both in the same directory).

**Example:**

```
string Destination = Path.Combine("$(BinaryOutputDir)", "EOSSDK-Win64-Shipping.dll");
string Source = Path.Combine("$(ModuleDir)", "Bin", "EOSSDK-Win64-Shipping.dll");
RuntimeDependencies.Add(Destination, Source);

```

Side Note:

`"$(ModuleDir)"` and the other string variables only work for `RuntimeDependencies.Add`, so don’t try using it for `PublicIncludePaths.Add` or any other .build.cs functions. For those, the `ModuleDirectory` variable is all you have as far as I know.

---

<div class="post-metadata">

**Author:** ![brunoleos](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@brunoleos](https://forums.unrealengine.com/u/brunoleos)\
**Post date:** [March 2, 2021, 7:58pm UTC](https://forums.unrealengine.com/t/specify-dll-location-using-plugin-in-cooked-project/436693/6 "2021-03-02T19:58:09Z")

</div>

Well, in the last part you say:

> Next, make the DLL a dependency so it gets copied automatically:

```
 string pluginDLLPath = PATH_TO_YOUR_DLL_FILE;
 string binariesPath = CopyToProjectBinaries(pluginDLLPath, Target);
 System.Console.WriteLine("Using Python DLL: " + binariesPath);
 RuntimeDependencies.Add(binariesPath);

```

But the DLLs are being copied by your function CopyToProjectBinaries, not automatically by adding it with RuntimeDependency.Add() at line 4.

Do you know why do you need that last line yet?
