I have a WCF project with a service library and console app for self-hosting. The service app requires managed and unmanaged libraries, which I include using NuGet based on this SO answer, Where to place dlls for unmanaged libraries?
This works fine when testing the library independently--all libraries are copied correctly to the service library output folder. However, when the console app is built, the unmanaged dll does not get copied into the console app's output folder and the app fails at runtime.
Question: How can I get the unmanaged dll to be lifted up/copied into any app that hosts the service library? I know I can do it by hand but would like an automated solution since I will likely add IIS hosting at least and don't want to take risk of forgetting to handcopy every time I build.
Here is my .nuspec file:
<?xml version="1.0"?>
<package>
<metadata>
<id>XyzLibrary</id>
<version>1.0.0</version>
<authors>Authors</authors>
<description>Description</description>
<releaseNotes>Notes</releaseNotes>
</metadata>
<files>
<file src="XyzLibraryNet.dll" target="lib\net461\"/>
<file src="XyzLibrary.dll" target="unmanaged"/>
<file src="build\XyzLibrary.targets" target="build" />
</files>
</package>
And here is the .targets file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CopyMyPackageFiles" AfterTargets="AfterBuild">
<ItemGroup>
<MyPackageFiles Include="$(MSBuildProjectDirectory)..\unmanaged\*.*"/>
</ItemGroup>
<Copy SourceFiles="@(MyPackageFiles)" DestinationFolder="$(OutputPath)">
</Copy>
</Target>
</Project>