I am writing an app in .NET Core that depends on native code using [DllImport]
. I have the native compiled library artifacts for win-x64, win-x86, and linux-x64.
My project structure is like:
MyApp
|--Main.cs
|--runtimes
|--win-x86
|--native
|--somelibrary.dll
|--win-x64
|--native
|--somelibrary.dll
|--linux-x64
|--native
|--libsomelibrary.so
I get then DLL not found exceptions when I run the app.
I have tried to use MSBuild targets solution here, but this only copies one dll
to the main output folder at compile time. However, I want to the output to include all three native libraries in the output folder in the same structure as the runtimes folder above, and leave the selection of the compatible native library to .NET Core runtime host.
So if the user runs the app in Windows x86, it will use the win-x86, and so on.
I have noticed when I reference native wrappers like SkiaSharp from NuGet, it will actually integrate nicely into my app, and will include all assets in a runtimes folder structure to work on multiple environments at runtime. How can I do this?
Edit:
I ended up creating a nuget package for the native library binding, and reference the nuget in my other projects.