I have an Asp.Net project (Vb.Net) that references a managed dll (library written in C#). That library project has several unmanaged dependencies dlls in a lib folder (copied into bin/Release/lib folder during build). The library is not a part of the main solution.
My library uses [DllImport] that references an unmanaged dll. But to let the unmanaged dll be found, I call SetDllDirectory():
string path = // don't know how to generate the path
SetDllDirectory(path);
I am struggling with generating the path to the unmanaged dll and its dependencies. I can start with my main project bin folder or something. But what should I do next? E.g. is there a way to copy the unmanaged dlls from the library's bin/Release/lib folder to my main project's bin folder? Or some other solution?
There are two ways you can go about this:
Add the Dlls to the VS project as a file, then set Build Action
to None
and Copy to output directory
as Copy
. This should ensure that any external dependencies of the referenced library are copied.
Add a command like xcopy "$(ProjectDir)lib\*.*" "$(OutDir)\" /y /e
or xcopy "$(ProjectDir)lib\*.*" "$(TargetDir)" /y
to the Build Events section in Project properties. This should copy the \lib directory from the project root to the output.