How to modify build file to copy DLLs to binaries?

How does one modify the build file to copy DLLs to the Binaries folder?

I have tried adding

    RuntimeDependencies.Add(new RuntimeDependency(Path.Combine(Path.Combine(LibPath, <mydll>))));

but that copies things that start in the ThirdParty folder into another ThirdParty folder when I package a game for shipping. How do I make things in the ThirdParty folder in the source tree show up in the Binaries folder when the game is packaged?

The reason I would like DLLs to show up in the Binaries directory is so that they are automatically found at runtime. I tried using something like

FPlatformProcess::GetDllHandle(myPath);

but that crashed the game even though I verified myPath existed.

Thanks,
-X

This is how I do it. Each Third Party lib uses a Build.cs file and the module is added as dependency in the main project’s Build.cs file.

Here is how the hypothetical module “YourLib” works.

YourLib.Build.cs:

using System;
using System.IO;
using UnrealBuildTool;

public class YourLib : ModuleRules
{
    public string GetUProjectPath()
    {
		//Change this according to your module's relative location to your project file. If there is any better way to do this I'm interested!
		//Assuming Source/ThirdParty/YourLib/
        return Directory.GetParent(ModuleDirectory).Parent.Parent.ToString();
    }

    private void CopyToBinaries(string Filepath, TargetInfo Target)
    {
        string binariesDir = Path.Combine(GetUProjectPath(), "Binaries", Target.Platform.ToString());
        string filename = Path.GetFileName(Filepath);

        if (!Directory.Exists(binariesDir))
            Directory.CreateDirectory(binariesDir);

        if (!File.Exists(Path.Combine(binariesDir, filename)))
            File.Copy(Filepath, Path.Combine(binariesDir, filename), true);
    }

    public YourLib(TargetInfo Target)
	{
		Type = ModuleType.External;

		Definitions.Add("WITH_YOURLIB=1");

		// Compile and link with YOURLIB

		PublicIncludePaths.Add(ModuleDirectory + "/include");
		PublicAdditionalLibraries.Add(ModuleDirectory + "/lib/YourLib.lib");
		CopyToBinaries(ModuleDirectory + "/lib/YourLib.dll", Target);
	}
}

Hope this helps!

2 Likes

Thanks for this answer. Very helpful. Sorry for slow response as I was on vacation. Thanks to for accepting on my behalf.