You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Copy runtime libraries from references project #765
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
Reacted by Brice Lambson, Alexandre Bossard, asmichi, Huo Yaoyuan, miterosan, Ghasan (غسان), Steven Brix, Victor Irzak, kiripon, Alex Rønne Petersen and 3 more
@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?
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.
@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?
@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.
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.
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.
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...
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.
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).
Activity
livarcocc commentedon Feb 3, 2017
@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?
livarcocc commentedon Feb 3, 2017
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:
livarcocc commentedon Feb 6, 2017
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.
dsplaisted commentedon Feb 6, 2017
@natidea @rrelyea @srivatsn @emgarten For this to work, I think we would want NuGet restore to write information about
Contentitems with Pack=true to the assets file. Does that sound right?emgarten commentedon Feb 6, 2017
@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.
rrelyea commentedon Feb 8, 2017
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.
srivatsn commentedon Feb 8, 2017
Given the scope of change this is post RTM.
1 remaining item
rwasef1830 commentedon Aug 14, 2017
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.
dabretin commentedon Jun 27, 2018
So ???
Apollo3zehn commentedon May 23, 2019
Is there any plan to solve this eventually? How can we have unit tests referencing a project which depends on native assemblies?
%userprofile%/.nuget/packagescache...Similar issues:
#1088
https://github.com/dotnet/cli/issues/7500
NuGet/Home#4514
Update dependencies from https://github.com/aspnet/AspNetCore build 2…
asmichi commentedon Jul 3, 2022
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.jsonand thus cannot be loaded byDllImport. Only NuGet libraries can haveruntimeTargets! Okay, then, trick the build to add runtime libraries into an existing NuGet library.silkfire commentedon Nov 24, 2022
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).michaelosthege commentedon Jan 18, 2023
Crossref #17527 appears to be a newer ticket specifically about lacking the
runtimesfolder when building for cross-platform.