Resolve native assemblies from NuGet package
See original GitHub issueIs your feature request related to a problem? Please describe.
I have a plugin with a dependency on Microsoft.CognitiveServices.Speech, which has native dependencies in the runtimes folder that are resolved per platform. When the P/Invoke call occurs from inside Microsoft.CognitiveServices.Speech after resolving the plugin with PluginLoader.CreateFromAssemblyFile
, I get a DllNotFoundException
.
Describe the solution you’d like
I’d like the PluginLoader
to also search the runtimes folder in the base path for the AssemblyLoadContext
so that I do not get the DllNotFoundException
for the native dependency.
Describe alternatives you’ve considered Haven’t started thinking about alternatives.
Additional context No additional context.
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Add native files from NuGet package to project output ...
I'm trying to create NuGet package for a .Net assembly which does pinvoke to a native win32 dll. I need to pack both...
Read more >Select Assemblies Referenced By Projects - NuGet
Our recommendation is to have one package per assembly, and package dependencies to other assemblies. When NuGet restores a project, ...
Read more >PackageReference in project files - NuGet
Details on the process through which a NuGet package's dependencies are resolved and installed in both NuGet 2. x and NuGet 3.
Read more >csproj: document how to properly pack platform-specific ...
New csproj additions -- I find the IncludeAssets value "Native" which says "native assemblies" will be copied over. So where are they? Nuget...
Read more >Creating a NuGet package with static dependencies AND ...
the package needs to reference a .net wrapper assembly that references a c++ native dll. And both the dlls (native and wrapper) needs...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @natemcmaster - the <TargetsForTfmSpecificContentInPackage> did the trick
Disclaimer first…if you’re not familiar with MSBuild targets, properties, and item groups, it’s probably better to use a nuspec file. I usually recommend nuspec for complex packing tasks because I think the “API” for customizing a package via csproj is awful.
Nuspec generation in csproj relies on MSBuild items to tell it what to pack. There are a few magic default settings which pick up build outputs for most simple class libraries and console tools. But the magic falls apart when you need to include generated content (such as a plugins folder). You can write your own magic by adding files to the
TfmSpecificPackageFile
item group as a part of a target that is listed in theTargetsForTfmSpecificContentInPackage
property. I haven’t tested this on my own, but I imagine the result would look something like this:By the way, checkout https://github.com/dotnet/sdk/blob/master/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.PackTool.targets and https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets to see what the SDK is doing under the hood.