Skip to content

csproj: document how to properly pack platform-specific native assemblies #6645

@yatli

Description

@yatli

Details about Problem

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe): dotnet.exe

dotnet.exe --version (if appropriate): 2.1.4

OS version (i.e. win10 v1607 (14393.321)): win10 v1709 (16299.248)

Description

We've got rid and tfm specific native assemblies in a package but until very recently I haven't find enough documentation about how to pack them and let the runtime pick the appropriate native library automatically.

Relevant links:

  • New csproj additions -- I find the IncludeAssets value "Native" which says "native assemblies" will be copied over. So where are they?
  • Nuget MSBuild targets -- traditional folders like build/, tools/, lib/, etc.
  • Fragmented information about project.json, mentioning runtimes/win-x64 and so on -- , but how am I supposed to know that this convention is carried over to the new csproj?

I have to look into the Nuget code repo, and here: https://github.com/NuGet/NuGet.Client/blob/023fe7670796a8986bbfdc520029e4cf0a6bbfda/src/NuGet.Core/NuGet.Packaging/ContentModel/ManagedCodeConventions.cs#L452

That's it, now I know it's runtimes/{rid}/native/{any?}. Searching for a concrete example on the internet:
I get issues, not documentation.
Searching for "nuget pack native assemblies" did not work either..
It turns out, the correct information is located here: - Bingo!
However, this page is advertised as "Supporting multiple .NET framework versions", which is really orthogonal to what I want. Multi-targeting is about tfm, and platform-specific stuff are about rid -- I have never found a single page that connects all these dots together.

So I suggest documenting such behavior at the following docs sites:

  1. "Additions to the csproj format" -- https://docs.microsoft.com/en-us/dotnet/core/tools/csproj
  2. "Package creation workflow" -- https://docs.microsoft.com/en-us/nuget/create-packages/overview-and-workflow -- there's multi-targeting page, and a native packages page, and I think it's better to create a new page "platform-specific native libraries" to avoid confusion.
  3. Also, document that runtimes/{rid}/native does not work with netfx -- you have to place native dlls in the lib/ folder (risky, could cause msbuild warnings/errors), or embed the dlls and release them at runtime.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions