-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolution of native libraries when using DllImport #19929
Comments
I also noticed the existence of --additional-deps, but I don't know how to make unit test runners use that parameter. |
/cc: @vitek-karas |
I can only comment on the runtime side of things:
|
This has been labeled as a question, which it is indeed, but only because I wouldn't want to make a feature request if there is already an existing solution. |
I second this. Same issue. Building a .NET Core library that includes some native files (from a VCXPROJ). Works fine when I add it to the produced NuGet package: consumers generate .deps.json files referencing the libraries. However, doesn't work in a Console app within the same solution using ProjectReference, nor in a Unit Test. Though, it should. The only issue is that hte generate .deps.json files for those other projects do not fold in the native assets of the ProjectReference. I would expect to be able to simply include Content (or None) item, and perhaps stick |
Digging into it, DependencyContextBuilder just seems to consider NuGet origins. Would need to fix that, as well as the associated GenerateDeps MSBuild task. And then the MSBuild targets to consider these items. |
Adding to this to say I have the same issue with my project Raylib-cs. Took me a while to notice the |
@marcpopMSFT I think this is very much an SDK issue.
|
FWIW, having a way to do this is essential for parts of vezel-dev/zig-sdk#8 as well. |
@vitek-karas Isn't this an issue in deps.json creation which from our discussion, the runtime team controls (hence our decision to move it to runtime repo)? |
@marcpopMSFT I agree with @vitek-karas that this is a dotnet/sdk issue. The .deps.json format already has a representation for the required concept. The task that generates the .deps.json is in the dotnet/sdk repo. The .NET SDK needs to provide a (either add or document an existing) mechanism for developers to specify native assets for a given RID. This work is definitely SDK work as the experience is in the SDK itself, not in the runtime. I'll let you two determine where this ends up. In any case, I think this falls into either Loader/Host or SDK since those are the areas that would own the discovery mechanism, not Interop. |
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov Issue DetailsTL;DR: How can I make -- If I create a NuGet package and put native DLLs in Now I would like to unit-test the classes in that package. Usually I put the unit test project in the same solution, make it refer to the project containing the classes to test. Unfortunately, that doesn't bring the mechanisms from A workaround would be to have a separate NuGet package containg nothing more than the native libraries, making the project containing .NET code refer to it, similar to what libgit2sharp does. However that's not convenient when updating the native libraries because it requires publishing their package before being able to test their integration in the .NET code. Is there any other way? Any thoughts?
|
While I agree that the final piece of code which writes this info into |
@richlander has been digging into the RID behaviors and so may have an opinion here on how this should work long term. |
Since this has been marked as a feature request, could you please advise on a better title? |
@antoinebj Thanks a lot for reminding us about this. I think the core of the problem is lack of support for RID specific assets our project system. That is things like:
I would suggest renaming this issue to something like "Support RID specific assets outside of NuGet packages" (or something similar). I'll move this issue back to the SDK repo where it belongs. |
Is there a chance that this issue (or something like what @vitek-karas described) might be prioritized for .NET 7? Having a way to include RID-specific assets combined with my upcoming work on project/package reference support in Zig.Sdk would be a game-changer for easily adding cross-compiled, in-box native components to any .NET app. |
I think the native binary resolution is just a symptom of a larger problem, which is that when consuming a project that builds a NuGet package as a |
just went straight into that issue. how is it to be handled now? build a local nuget just to reference it later? |
Moving to backlog. This relates to P2P references and native dependencies. Probably could use @richlander doing a pass through this as there isn't a good way to produce packages and projects that have native dependencies in a way that will work well for customers |
We're doing something to solve this in IKVM. But it involves our own P2P implementation, and build time modification of deps.json. so, not great. |
I'd really urge prioritizing this issue. .NET has an excellent interop story these days ... except when it comes to everything build-related. Resolving this issue would bring the story from excellent to amazing. It would also make life massively simpler for those of us who are maintaining MSBuild SDKs that bridge managed and native code. |
TL;DR: How can I make
DllImport
automatically load the right native library from theruntimes/<rid>/native
path when it is in a project referred byProjectReference
, similar to whatPackageReference
enables by adding the appropriate resolution information in deps.json?--
If I create a NuGet package and put native DLLs in
runtimes/<rid>/native/
, the deps.json file generated for the assembly referencing that package will getruntimeTargets
entries for the native libraries, allowingDllImport
to find the appropriate DLLs to load. That mechanism is very useful for easily targeting multiple platforms with "Any CPU" despite reliance on native libraries that are each specific to a platform/architecture combination.Now I would like to unit-test the classes in that package. Usually I put the unit test project in the same solution, make it refer to the project containing the classes to test. Unfortunately, that doesn't bring the mechanisms from
PackageReference
, as it only uses aProjectReference
. Therefore the deps.json for the unit test assembly doesn't get hints for the native libraries, and when the unit test is run, it complains about not finding the native DLLs.A workaround would be to have a separate NuGet package containg nothing more than the native libraries, making the project containing .NET code refer to it, similar to what libgit2sharp does. However that's not convenient when updating the native libraries because it requires publishing their package before being able to test their integration in the .NET code.
I know about the NativeLibrary class where one can register a custom resolver, but that seems tedious for true multiplatform. I didn't find a simple way to replicate the RID-based resolution.
Is there any other way? Any thoughts?
The text was updated successfully, but these errors were encountered: