Search code examples
c#c++nuget.net-coremultiplatform

Create NetCore NuGet package with native dependency


I made a NetCore wrapper in C# for a C++ library; this library has specialized builds for Windows, Linux and MacOS. We added a C# wrapper for it which also works on all these OSes.

From what I read in the MSDN docs, it is possible to add multi target dependencies, but that works at the framework level, not OS. So it would be NetCore for all cases, and this wouldn't work.

The native binary is quite big (about 20 MB), so it would be bothersome to make a single NuGet package with all the native binaries... Any suggestion?


Solution

  • I ended up using the Conan C++ package manager to bring in the native .dll or .so after building the C# layer.

    To target multiple frameworks, just use TargetFrameworks (plural) in .csproj. This works for both VS and VSCode.

    To create a NuGet package with MSBUild targets that call Conan, I followed these steps.