question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resolve native assemblies from NuGet package

See original GitHub issue

Is 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:closed
  • Created 4 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rozelecommented, Aug 21, 2019

Thanks @natemcmaster - the <TargetsForTfmSpecificContentInPackage> did the trick

0reactions
natemcmastercommented, Aug 18, 2019

I can setup a .nuspec file to get the plugins folder, but I was wondering if you had any tips / ran into this issue and figured out how to inform MSBuild to include the plugins folder without creating a .nuspec.

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 the TargetsForTfmSpecificContentInPackage property. I haven’t tested this on my own, but I imagine the result would look something like this:

<PropertyGroup>
  <TargetsForTfmSpecificContentInPackage>BuildPlugin;$(TargetsForTfmSpecificContentInPackage)</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
 
<Target Name="BuildPlugin" BeforeTargets="CoreBuild">
  <PropertyGroup>
    <MyPluginOutputPath>$(OutputPath)/plugins/MyPlugin/</MyPluginOutputPath>
  </PropertyGroup>

  <MSBuild 
    Projects="..\MyPlugin\MyPlugin.csproj"
    Targets="Publish" 
    Properties="Configuration=$(Configuration);PublishDir=$(MyPluginOutputPath)" />

  <ItemGroup>
    <TfmSpecificPackageFile Include="$(MyPluginOutputPath)**/*">
      <PackagePath>tools/$(TargetFramework)/any/plugins/MyPlugin/</PackagePath>
    </TfmSpecificPackageFile>
  </ItemGroup>

</Target>

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found