How to add external native dependency dll?

Denis picture Denis · May 7, 2013 · Viewed 61.5k times · Source

I have two projects. First is a Windows Forms Application project and second is a class library project. Сlass library project works with FANN. Windows Forms is Startup Project.

I should have Fann.Net.dll and fanndoubleMT.dll to work with the FANN. I downloaded these libraries and put their in a folder lib, located in the root of the solution.

I added Fann.Net.dll as external dll to the class library project. I compiled the project. I got an error that says "Unable to load DLL 'fanndoubleMT.dll'. I fixed this error by adding fanndoubleMT.dll to the folder Windows_Forms_Application\bin\Debug.

I think this is a terrible solution to the problem, because I use git, and every time you need to transfer dll to this folder on the new workplace.

Sincerely, Denis.

Answer

liang picture liang · Oct 19, 2013

You may try this:

  1. Add/Existing Item, instead of Add Reference.
  2. Use Add As Link.
  3. Make sure the item is to be copied in build folder. In the property of the library in VS, set Build Action to Content and Copy to Output Directory to Copy if Newer.
  4. Done. Rebuild and test.

Suggested in the link http://social.msdn.microsoft.com/Forums/en-US/1b1b316a-8648-4243-a651-84de51fd2508/reference-native-dll-from-managed-c-project?forum=vssmartdevicesvbcs.