title: How do you include a pinvoked dll in a NuGet package?
body: <p>I'm making <a href="https://www.nuget.org/packages/PicNet.XGBoost/" rel="nofollow noreferrer">this</a> NuGet package (<a href="https://github.com/PicNet/XGBoost.Net/tree/master/XGBoost" rel="nofollow noreferrer">source</a>) which pinvokes a dll <code>libxgboost.dll</code> (which is built from <a href="http://xgboost.readthedocs.io/en/latest/build.html" rel="nofollow noreferrer">XGBoost</a>). However, it's currently throwing an exception because it cannot locate <code>libxgboost.dll</code>.</p>
  
  <p>How do I include <code>libxgboost.dll</code> into my NuGet package so I can pinvoke it?</p>
  
  <p><strong>Calling Code (with Package Installed)</strong></p>
  
  <pre><code>using System;
  using XGBoost;
  
  namespace TestXGBoostPackage
  {
      class Program
      {
          static void Main(string[] args)
          {
              XGBRegressor r = new XGBRegressor();
              float[][] X = new float[2][];
              X[0] = new float[2];
              X[0][0] = 0;
              X[1] = new float[2];
              X[1][0] = 1;
              float[] y = {0, 1};
              r.Fit(X, y);
              Console.ReadKey();
          }
      }
  }
  </code></pre>
  
  <p><strong>Exception Thrown by Calling Fit()</strong></p>
  
  <pre><code>An unhandled exception of type 'System.DllNotFoundException' occurred in XGBoost.dll
  
  Additional information: Unable to load DLL 'libxgboost.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
  </code></pre>
  
  <p><strong>DLL Import Statement for Function PInvoked by Fit()</strong></p>
  
  <pre><code>[DllImport("libxgboost.dll")]
  public static extern int XGDMatrixCreateFromMat(float[] data, ulong nrow, ulong ncol, 
                                                  float missing, out IntPtr handle);
  </code></pre>
  
  <p><strong>nuspec File for Package</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;package &gt;
    &lt;metadata&gt;
      &lt;id&gt;PicNet.XGBoost&lt;/id&gt;
      &lt;version&gt;0.0.2.1&lt;/version&gt;
      &lt;title&gt;XGBoost.Net&lt;/title&gt;
      &lt;authors&gt;John Smith&lt;/authors&gt;
      &lt;owners&gt;John Smith&lt;/owners&gt;
      &lt;licenseUrl&gt;http://www.apache.org/licenses/LICENSE-2.0&lt;/licenseUrl&gt;
      &lt;projectUrl&gt;https://github.com/PicNet/XGBoost.Net&lt;/projectUrl&gt;
      &lt;iconUrl&gt;http://www.picnet.com.au/wp-content/uploads/2015/01/logo-dark.png&lt;/iconUrl&gt;
      &lt;requireLicenseAcceptance&gt;false&lt;/requireLicenseAcceptance&gt;
      &lt;description&gt;.Net wrapper for the XGBoost machine learning library.&lt;/description&gt;
      &lt;releaseNotes&gt;test dll dependency fix&lt;/releaseNotes&gt;
      &lt;copyright&gt;Copyright 2016&lt;/copyright&gt;
      &lt;tags&gt;machine learning xgboost boosted tree&lt;/tags&gt;
    &lt;/metadata&gt;
  &lt;/package&gt;
  </code></pre>
  
  <p>In the package's project properties, the build output path is <code>bin\Debug\</code> and the platform target is <code>x64</code>.</p>