views:

48

answers:

2

So far I've been placing the dll into the /bin folder because it seems to be the only place it will get loaded when a DllImport'd function is called, but it just doesn't feel right since it's the output folder and it'll probably be wiped after a 'project clean' or 'rebuild all' operation.

How should I do this? Thanks in advance.

Note: I cannot embed the .dll into the .exe because the author explicitly wants the dll to be visible from the outside.

+1  A: 

Use VS to create a new folder in your project called Lib. Copy your DLLs there and reference them from there.

Jay Riggs
Referencing works only for managed DLLs (or COM DLLs, but in that case the reference is actually to the tlbimp/aximp-ed managed wrapper, and the COM DLL is not copied (because it is presumed to be registered)).
itowlson
Would it work if I explicitly reference the DLL path as in DllImport( "Lib/xxx.dll" ) ?
Trap
+2  A: 

Try this:

  • Create a folder into your project
  • Place your unmanaged assemblies in there
  • Change "Copy to Output Directory" to "Copy If Newer" at Properties tab.
Rubens Farias
Okay. But don't create a new folder, the app still won't be able to find the DLLs. And use Copy If Newer, the app isn't going to change the DLLs.
Hans Passant
I suggest to create that folder to separate that files; will it create same folder on output directory?
Rubens Farias