Publishing application with native libraries
Hey.
I'm trying to create an application that depends on some native shared libraries (written in C++). I created a
NativeLibraries
project that contains the required shared libraries as Content
elements in .csproj
:
Then my main application depends on this NativeLibraries
project. When I build it, everything is fine, the native libraries are nicely placed in runtimes/*
folder in the build directory of the main application.
Problem is that the libraries are not copied to the output directory directly for rid-specific publishing (dotnet publish -r linux-arm
) but are still present in runtimes/linux-arm/native
folder. Unlike for example SkiaSharp (that I also use). The native libraries of SkiaSharp are correctly copied directly to the publish output directory. SkiaSharp doesn't seem to be particularly clever here:
And the PackageFile
is expanded as follows:
Which is similar to my Content
element. I tried adding this Pack
as well but it didn't help.
Probably, SkiaSharp is doing something else that I don't see here. What may it be?
Microsoft docs mostly talk about packaging native libraries as Nuget packages which is not the case for me. Thanks5 Replies
My MSBuild-foo wasn't good enough to figure out what more is SkiaSharp doing 😦
Pack only works in NuGet AFAIK
You would probably want
CopyToOutputDirectory
It's there in my
Content
entry. And it is copied, but on publish, the libraries aren't moved from runtimes/[rid]/native
to the output directory directly. You mean that I need CopyToOutputDirectory
in another place?Contents aren't directly copied
So put a
CopyToOutputDirectory
to themI got them already in the project that defines them:
Do you mean that I also need to have the copying in the consumer, the end-application that's getting packaged?
Possibly SkiaSharp is doing some Nuget-specific magic that I don't know about
I hoped that publish does some automatic copying based on runtimeid folders in
runtimes/
but apparently not
It seems that this magic is related to the contents of obj/project.assets.json
. If something is runtimeTargets
there, then MSBuild knows to copy it to proper place. But it seems to be done like that only for Nuget packages :/