0

I have 2 repositories: one builds a native dll, and the second consumes the native dll via pinvoke (not a reference).

Currently just to get me by, I'm literally just copying the built native dll into my second repo's project's build output folder.

What is the better longterm method?

My current consideration is to ship the native dll as a nuget package, but can managed projects take nuget packages for native dlls? Even if it can, what settings do I have to enable so that it does a copy of the native dll to my build output directory instead of trying to add it as a reference (which isn't possible anyway)?

user3338893
  • 917
  • 3
  • 10
  • 17
  • 2
    There are two options you see when you right click a file added to a solution or project in VS. Build Action and Copy to Output Directory. If you don't go th nuget route, I am sure you can add the file to a solution folder and Set the Build Action to "None" and Copy to Output Directory to "Copy Always" to get this to work. – Ross Bush Dec 13 '18 at 21:19
  • Expounding on what **Ross Bush** said, having the `.dll` in the same directory as the main executable is generally preferred over, and is easier than, attempting to manage it through nuget packages. – absoluteAquarian Dec 13 '18 at 21:22
  • It depends on how you want to package your app on the target machine. Native libraries should go to system path in general, and usually people use technologies like MSI. Then on development machines, you use post build event to do the same by copying the native libraries to system path (such as `%windir%\system32`). – Lex Li Dec 13 '18 at 22:10
  • I don't have a full answer to your question, BUT @LexLi is on the right track for the most part. IF you need multiplatform support, I would suggest looking at how the Libuv package on nuget is assembled; It provides support for a number of different runtimes (win/linux/osx,32/64 bit...) for consumption by managed libraries (such as DotNetty and Kestrel) – to11mtm Dec 13 '18 at 23:22
  • https://stackoverflow.com/a/28771413/17034 – Hans Passant Dec 13 '18 at 23:45
  • You can use this "link resource" technique to embed native dlls into .NET binaries: https://stackoverflow.com/questions/52674116/c-sharp-wrapper-library-around-unmanaged-dll-requires-unmanaged-dll-to-be-in-sam – Simon Mourier Dec 14 '18 at 09:32

0 Answers0