Skip to content

How to consume native dependencies via ProjectReference? #10575

Open

Description

@huoyaoyuan

Opening at this repository because requiring something like dotnet/cli#1841.

Steps to reproduce

We are publishing some native dependencies via csproj:

  <ItemGroup>
    <NativeLibs Include="$(MSBuildThisFileDirectory)runtimes\**\*.dll*" />
    <NativeLibs Include="$(MSBuildThisFileDirectory)runtimes\**\*.so" />
    <NativeLibs Include="$(MSBuildThisFileDirectory)runtimes\**\*.a" />
    <NativeLibs Include="$(MSBuildThisFileDirectory)runtimes\**\*.dylib" />
    <None Include="@(NativeLibs)">
      <Pack>true</Pack>
      <PackageCopyToOutput>true</PackageCopyToOutput>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Include="_._">
      <Pack>true</Pack>
      <PackagePath>lib/netstandard2.0</PackagePath>
    </None>
  </ItemGroup>

The native libraries are correctly packaged into runtimes\win-x64\native\*.dll and other rids.
A test application sits in the same repository, using ProjectReference to consume the library.
The test application's .deps.json is missing entry for native dependencies, causing them failed to load at runtime.
However, if I put the nupkg into local source and consume it via PackageReference, it's getting native libraries in .deps.json.

Are we packaging it in the wrong way? What's the standard packaging to consume by source?
I cannot find a popular library consuming native packages via project reference. Looked SQLitePCLRaw.lib.e_sqlite3 and runtime.native.System.Data.SqlClient.sni, their tests are consuming them via PackageReference.

Environment data

dotnet --info output:

.NET Core SDK(反映任何 global.json):                                                                                   Version:   3.0.100
 Commit:    04339c3a26

运行时环境:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100\

Host (useful for support):
  Version: 3.0.0
  Commit:  7d57652f33

.NET Core SDKs installed:
  3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Activity

  1. transferred this issue fromdotnet/clion Jan 31, 2020
  2. github-actions commented on Sep 22, 2025

    @github-actions
    Contributor

    Due to lack of recent activity, this issue has been labeled as 'Stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.

  3. carlreinke commented on Sep 22, 2025

    @carlreinke

    We are still waiting for a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions