We are accessing DB2 from C# using IBM's DB2 libraries https://www.nuget.org/packages/IBM.Data.DB2.Core/
We want to wrap IBM's library in a library of our own, adding DB2 related functionality to application developers.
The problem is that IBM's library is based on native dll's which are included in their package. However these native dll's are not copied to build output folder when IBMs library is only indirectly referenced through our own DB2 wrapper library
I suspect that I need to include the native dll's in our own library. Only I am not sure how to do that.
The nuget package we create of our wrapper library is created from the csproj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.0</Version>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IBM.Data.DB2.Core" Version="1.3.0.100" />
</ItemGroup>
</Project>
It's complicated. NuGet has two ways to consume packages, and the two ways work somewhat differently. The original way was with packages.config
(PC) and the new way is PackageReference
(PR).
NuGet with PC has no concept of runtimes, so they way it's often implemented, and having a quick look at the package, it appears this is the case, the package author bundles MSBuild props and/or targets files in the package, and these targets modifies the build to copy the native files on build. A project using PC, when a package is installed, all dependencies are also installed, so all packages are direct dependencies of the project and any build targets in packages are imported into the project.
Projects using NuGet with PR on the other hand can reference just their direct dependencies, but dependencies of packages come in transitively. NuGet only tells MSBuild to import build targets from direct dependencies, not transitive dependencies. So that explains the behaviour you're seeing.
In NuGet 5.0 (released with Visual Studio 2019, and I can't remember which versions of .NET Core SDK), we added a buildTransitive
feature that will pull in build props/targets from transitive packages. However it requires the package author to reauthor their packages to use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With