I have a .NET Standard 2.0 C# project Foo that produces a NuGet package with the following directory structure:
build/ x64/ FooNative.dlllib/ netstandard2.0/ FooManaged.dll Foo.dllfoo.nuspec
The project relies on a managed DLL (FooManaged.dll), which wraps a native DLL (FooNative.dll).
I then add a reference to this Foo.nupkg package from another C# project Bar.csproj: all works fine, except the build output of Bar contains only the managed DLL, not the native one. I have tried many ways to alter the Foo.csproj, so that the package will ensure the DLL is copied to the output folder at during build time of Bar. Below are the relevant parts of the Foo.csproj:
<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFrameworks>netstandard2.0</TargetFrameworks><OutputType>Library</OutputType><RootNamespace>Foo</RootNamespace><AssemblyName>Foo</AssemblyName><GenerateAssemblyInfo>false</GenerateAssemblyInfo><Platforms>x64</Platforms><version>0.0.0</version></PropertyGroup><PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"><OutputPath>bin\x64\Release\</OutputPath><CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet><LangVersion>6</LangVersion></PropertyGroup><PropertyGroup><AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects></PropertyGroup><!-- bundle wrapped .dlls into the nupkg --><ItemGroup><Content Include="ThirdParty/FooManaged.dll"><Pack>true</Pack><PackagePath>lib/netstandard2.0</PackagePath></Content><Content Include="ThirdParty/FooNative.dll"><Pack>true</Pack><PackagePath>build/x64</PackagePath></Content></ItemGroup><ItemGroup><Reference Include="Foo"><HintPath>ThirdParty\FooManaged.dll</HintPath></Reference></ItemGroup><ItemGroup><ContentWithTargetPath Include="ThirdParty\FooNative.dll"><CopyToOutputDirectory>Always</CopyToOutputDirectory><TargetPath>FooNative.dll</TargetPath></ContentWithTargetPath></ItemGroup></Project>
Here, the CopyToOutputDirectory
tag seems not to have the desired effect.
How can I ensure the DLL is copied to the build output directory as required?
Note: we are using dotnet pack
to package Foo.