I have a NuGet package that contains one managed DLL and a bunch of native DLLs. The managed DLL calls into the native DLLs using pinvoke. I have successfully packaged everything into a NuGet package with the following directory structure:
lib
Managed.dll
build
Unmanaged1.dll
Unmanaged2.dll
MyNuGetID.targets
My .targets file looks like this
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<NativeLibs Include="$(MSBuildThisFileDirectory)*.*" />
<None Include="@(NativeLibs)">
<Link>%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Everything I have described so far follows the instructions found here. From what I have read, when visual studio installs this NuGet package, it should insert an "Import Project" section in my .csproj file that reads in my .targets file and then copies all of my unmanaged DLLs into my bin\Debug
directory. I have done this successfully in the past using Visual Studio 2015, but for some reason with my current setup using Visual Studio 2012 it is not working. My NuGet package gets installed and a Reference Include=Managed...
section gets added to my .csproj file, but the .targets file is never Import
ed and my unmanaged DLLs never get copied over.
Notes:
- My .targets file has the same name as my NuGet package ID.
- My Visual Studio installation uses NuGet version 2.0
- I suspect the issue has something to do with my version of Visual Studio or NuGet.