I'm trying to create NuGet package for a .Net assembly which does pinvoke to a native win32 dll. I need to pack both the assembly and the native dll with the assembly added to the project references (no problem at this part) and the native dll should be copied into the project output directory or some other relative directory.
My questions are:
- How do I pack the native dll without visual studio trying to add it into the references list?
- Do I have to write an install.ps1 for copying the native dll? If so how can I access the package content for copying it?
It's a bit late but I've created a nuget package exaclty for that.
The idea is to have an additional special folder in your nuget package. I'm sure you already know Lib and Content. The nuget package I've created looks for a Folder named Output and will copy everything which is in there to the projects output folder.
The only thing you have to do is add a nuget dependency to the package http://www.nuget.org/packages/Baseclass.Contrib.Nuget.Output/
I've written a blog post about it: http://www.baseclass.ch/blog/Lists/Beitraege/Post.aspx?ID=6&mobile=0
There's a pure C# solution which I find rather easy to use and I don't have to bother with NuGet limitations. Follow these steps:
Include the native library in your project and set its Build Action property to
Embedded Resource
.Paste the following code into class where you PInvoke this library.
Call this method from the static constructor like as follows
UnpackNativeLibrary("win32");
and it will unpack the library to disk just before you need it. Of course, you need to be sure that you have write permissions to that part of the disk.I can't solve your exact problem, but I can give you a suggestion.
Your key requirement is : "And have it not auto-register the reference".....
So you'll have to to become familiar with "solution items"
See reference here:
Adding solution-level items in a NuGet package
You'll have to write some powershell voodoo to get the copy of your native dll into its home (again, because you do NOT want the auto-add-reference voodoo to fire)
Here is a ps1 file I wrote.....to put files in a third party references folder.
There is enough there for you to figure out how to copy your native dll to some "home"...without having to start from scratch.
Again, its not a direct-hit, but its better than nothing.