The way I have done this is to store the DLL in a path within the
project and use the SetDllDirectory method to tell my application where to
look for the DLL.
Here is my example:
PInvoke Signature for SetDllDirectory()
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetDllDirectory(string lpPathName);
Constructor for the class that contains the
var currentWorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
string path = Path.Combine(cwd, @"HereGoesYourRelativeFilepath");
On the properties of my DLL I have the "Copy To Output Directory"
property set to "Copy Always" so I know that it will always be in the
relevant folder in my bin directory after a build, so my relative filepath
points to there and all is well.
Hope this helps