I have a Visual Studio C# project that utilizes 3rd party C++ DLLs. Up until now there have been only 3 of these DLLs and so it hasn't bothered me to place these in the root folder of my project with the following properties:
Build Action: None
Copy to Output Directory: Copy Always
This results in the DLLs being copied to the project's /bin
folder and all works fine - they do not appear in the published project's root folder. I reference these 3rd party DLLs like this:
public class MyDLL
{
[DllImport("My_DLL.dll",
EntryPoint = "?Unit@@YA?AUOutput@@UInput@@@Z",
CallingConvention = CallingConvention.Cdecl)]
public static extern MyDLLOutput Unit(MyDLLInput UnitInput);
}
Recently I've been provided with several dozens of additional DLLs. I do not reference these directly from within my app - these DLLs are used by one of the 3 DLLs I reference using DllImport()
.
Placing all of these support DLLs in the root folder of the project now becomes an issue with me as it clutters the project. I've tried placing them inside a folder structure such as:
/ExternalDLLs/DLL1/dll1.dll
/ExternalDLLs/DLL1/SupportDlls/1.dll
...
/ExternalDLLs/DLL1/SupportDlls/24.dll
/ExternalDLLs/DLL2/dll2.dll
/ExternalDLLs/DLL3/dll3.dll
This results in a published folder structure of:
/bin/ExternalDLLs/DLL1/dll1.dll
/bin/ExternalDLLs/DLL1/SupportDlls/1.dll
...
/bin/ExternalDLLs/DLL1/SupportDlls/24.dll
/bin/ExternalDLLs/DLL2/dll2.dll
/bin/ExternalDLLs/DLL3/dll3.dll
The published folder structure doesn't work with my DllImport()
declaration. I presume this is because the DllImport()
is expecting these to be directly underneath /bin/
.
I don't mind a folder structure underneath /bin/
if necessary. I also don't mind if every DLL is copied to /bin/
without any folder structure - though I can't seem to find how to do that since the folder structure is also being copied to /bin/
.
Can anyone point me on the best approach to overcome this? I don't see an attribute for DllImport()
to specify a path. I'm sure this is a simple task, but I've never done it before. Hope I explained the problem well enough!
Thx.