Skip to content

Copy runtime libraries from references project #765

Open

Description

@alexandero-brd

I have Library.csproj with following code:

<ItemGroup>
    <Content Include="runtimes\win7-x86\native\**\*">
      <PackagePath>.</PackagePath>
      <Pack>true</Pack>
    </Content>
</ItemGroup>

When I run dotnet pack, I can see native dll-s in the generated package.
If I reference this NuGet package (using my own feed) in the another project then all libraries are correctly placed into bin folder. But if I reference this project directly then libraries are not copied.

We need to have one uniform way to add native libraries into project and use them in all scenarios:

  • Directly in this project
  • In other project that references this project
  • In the generated NuGet package

Activity

  1. self-assigned this
    on Feb 3, 2017
  2. livarcocc commented on Feb 3, 2017

    @livarcocc
    Contributor

    @ORYOL I just tried this as your described. And while I see the dlls under runtimes/win7-x86/native show app at the root of the package, as indicated by the PackagePath, I don't see them being copied in the output of applications that reference this package.

    Did you do anything different from what is described here to achieve that?

  3. livarcocc commented on Feb 3, 2017

    @livarcocc
    Contributor

    The way that I managed to get this to show up during a publish of a dependent up was to do this in the lib before packaging it:

    <PackagePath>lib\$(TargetFramework)</PackagePath>
    
  4. livarcocc commented on Feb 6, 2017

    @livarcocc
    Contributor

    We need a NuGet fix before continuing this. I chatted with @dsplaisted and his suggestion is that NuGet should generate the assets.json reference to project B in a similar manner for both ProjectReference and PackageReference. Once NuGet does that, the SDK can use that information to move the files.

  5. dsplaisted commented on Feb 6, 2017

    @dsplaisted
    Member

    @natidea @rrelyea @srivatsn @emgarten For this to work, I think we would want NuGet restore to write information about Content items with Pack=true to the assets file. Does that sound right?

  6. emgarten commented on Feb 6, 2017

    @emgarten
    Member

    @dsplaisted we need restore to find all assets that would be packed for each project, restore could then determine which assets are used and write those to the assets file. Build would then need to use only these assets for the project, the same as if it were a package.

    I've added more details on this in the NuGet issue tracking this.

  7. rrelyea commented on Feb 8, 2017

    @rrelyea
    Contributor

    What is the timeframe you guys are hoping to fix this? (don't see one).
    In the linked nuget issue, we explain that we believe this kind of change is out of scope for rtm.
    wanted to confirm that the work needed here can come later.

  8. added this to the 1.1 milestone on Feb 8, 2017
  9. srivatsn commented on Feb 8, 2017

    @srivatsn
    Contributor

    Given the scope of change this is post RTM.

  10. modified the milestones: , 1.1 on May 15, 2017
  11. modified the milestones: 2.1.0, on May 25, 2017
  12. 1 remaining item

  13. rwasef1830 commented on Aug 14, 2017

    @rwasef1830

    Any csproj hacks or workarounds for this in the short term ? This is very painful for unit test projects that are trying to test a library that has a native dependency.

  14. dabretin commented on Jun 27, 2018

    @dabretin

    So ???

  15. Apollo3zehn commented on May 23, 2019

    @Apollo3zehn

    Is there any plan to solve this eventually? How can we have unit tests referencing a project which depends on native assemblies?

    • I don't like the solution to create a separate package containing only the native libs and then referencing this package since then one has to publish them one after another, which makes CI difficult.
    • In the unit test project I tried to create a PackageReference instead of a ProjectReference. With the package reference I can point to the locally generated .nupkg. But this only works once since the second time this package is resolved from the %userprofile%/.nuget/packages cache...

    Similar issues:

    #1088
    https://github.com/dotnet/cli/issues/7500
    NuGet/Home#4514

  16. modified the milestones: 2.3.0, Backlog on Aug 27, 2021
  17. asmichi commented on Jul 3, 2022

    @asmichi

    I have made an extreme hack to add runtime libraries into deps.json: https://github.com/asmichi/DotNetInjectNativeFileDepsHack
    WARNING: This will likely break in a future version of the .NET SDK.

    The problem is that runtime libraries from reference projects do not appear in deps.json and thus cannot be loaded by DllImport. Only NuGet libraries can have runtimeTargets! Okay, then, trick the build to add runtime libraries into an existing NuGet library.

  18. silkfire commented on Nov 24, 2022

    @silkfire

    Another thing that doesn't seem to be possible at the moment is specifying a subdirectory where the native library ends up after publish. Right now they're all emitted to the root (/publish/) directory, regardless if they reside in a subdirectory inside the NuGet package itself (/runtimes/<arch>/native/sub1/sub2/mylib.dll).

  19. michaelosthege commented on Jan 18, 2023

    @michaelosthege

    Crossref #17527 appears to be a newer ticket specifically about lacking the runtimes folder when building for cross-platform.

  20. added
    native-assets
    on Jan 30, 2024
  21. added theissue type on Aug 12, 2026
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

    Area-NetSDKnative-assets

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions