I have a nuget that has the following structure:
Lib
-> net45
-> MyDll.dll
Runtimes
-> win10-x64
-> native
dependency1.dll
dependency2.dll
dependency3.dll
I add this nuget to one of my projects. Whenever I build that project, I expect ALL dlls to be copied into the output directory. However, only 'MyDll.dll' gets copied, and all the dlls from the native Runtimes folder don't. I've seen this post that explains how to use a .targets file to accomplish this: Add native files from NuGet package to project output directory. However, I can't find concrete information on how to add .targets file and this post is 6 years old. Surely something new/better exists by now?
Basically, what's the best way to copy native dlls into a build's output directory?
This really depends if your client project is native or managed.
If your project is native one, what you need to do is the following:
nuget pack YourPackage.nuspecThis will create a new nuget package that upon consuming in the native projects should work.UPDATE Important note: In the last part of .targets file you have to name variable that holds the file names you are copying to output folder. Don't give this variable generic name 'NativeLibs' because if you will have more than 1 native nuget package, there will be a conflict in VS on loading projects that use the package.
To avoid conflicting names, give it a unique name. Something like YourPackageNativeLibs will work. So the last part will look like: