title: How to include native assets in Nuget on multiple platforms, only 64-bit
body: <p>I'm creating a NuGet package with the following idea:</p>
  
  <ul>
  <li>Has a platform dependent executable and a dll (Windows, Linux and MacOS).</li>
  <li>The native binaries are 64-bit ones.</li>
  <li>A .NET Standard 2.0 library to use these native resources.</li>
  <li>During .NET library development and testing the native resources should be included in the build so they're usable.</li>
  </ul>
  
  <p>The idea isn't to embed the native resources and then extract them but distribute alongside the .NET library that makes use of them. However, I've come across some problem I'd like to ask around a bit.</p>
  
  <p><strong>1.</strong> Is there a commonly accepted convention to the root to external dependencies? Currently, my structure is:</p>
  
  <pre><code>.\Solution.sln
  .\Solution.nuspec
  .\runtimes\win-x64\native\&lt;.exe and .dll&gt;
  .\Project\Project.csproj
  </code></pre>
  
  <p>and this .NET Standard 2.0 library project compiles to <code>Project\bin\Debug\netstandard2.0</code>. I wonder though if there's some other convention or name for the root. I have read, amongst other sources and GitHub projects <a href="https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package" rel="noreferrer">Creating NuGet packages</a>.</p>
  
  <p><strong>2.</strong> Taking the <code>.nuspec</code> file is otherwise quite ordinary, I wonder how should I arrange the file references? I read the instructions at <a href="https://docs.microsoft.com/en-us/nuget/reference/nuspec#replacement-tokens" rel="noreferrer">Nuspec replacement tokens</a> and in the <code>.nuspec</code> file I have a section telling:</p>
  
  <pre><code>&lt;files&gt;
    &lt;file src="bin/$configuration$/$id$.pdb" target="lib/netstandard20" /&gt;
    &lt;file src="bin/$configuration$/$id$.dll" target="lib/netstandard20" /&gt;
    &lt;file src="runtimes/win-x64/native/.exe" target="runtimes/win-x64/native/.exe" /&gt;
    &lt;file src="runtimes/win-x64/native/.dll" target="runtimes/win-x64/native/.dll" /&gt;
  &lt;/files&gt;
  </code></pre>
  
  <p>but the native files do not get included. That's true also when I try to set a relative path starting with <code>..\</code> (I still may have this wrong, might just sleep over this a bit and try again).</p>
  
  <p><strong>3.</strong> Should I include some sort of a <code>.props</code> file that would then include both the wrapper and native resources correctly to those who use the Nuget library? It should be set up so that both files that all native resources are included and set so they're copied to project output along with other build artifacts.</p>
  
  <p><strong>4.</strong> Should I make some special arrangement to <code>Project.csproj</code>? Or maybe a better question is, is there some robust practice I should be aware of? I see there are questions and answers such as at <a href="https://github.com/aspnet/websdk/issues/204#issuecomment-302482115" rel="noreferrer">https://github.com/aspnet/websdk/issues/204#issuecomment-302482115</a>. Or in fact <a href="https://stackoverflow.com/questions/46361127/automaticaly-copy-native-dll-to-the-bin-folder-of-referencing-project-in-visual">Automaticaly copy native dll to the bin folder of referencing project in Visual Studio</a> and <a href="https://stackoverflow.com/questions/40104838/automatic-native-and-managed-dlls-extracting-from-nuget-package">Automatic native and managed DLLs extracting from Nuget Package</a> too.
  I should mention in <code>Project.csproj</code> I have only set:</p>
  
  <pre><code>&lt;PropertyGroup&gt;
    &lt;RuntimeIdentifiers&gt;win-x64;osx.10-11-x64;ubuntu.16.04-x64;debian.8-x64&lt;/RuntimeIdentifiers&gt;
    &lt;GeneratePackageOnBuild&gt;false&lt;/GeneratePackageOnBuild&gt;
  &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p><strong>edit:</strong> Doh! I'm trying to create the package by <code>dotnet pack .\Project\Project.csproj</code>, which doesn't use the <code>.nuspec</code> file. Maybe a good way is to use the Nuget metadata tooling as described at <a href="https://docs.microsoft.com/en-us/dotnet/core/tools/csproj" rel="noreferrer">Additions to the csproj format for .NET Core</a>.</p>
  
  <p><strong>edit 2:</strong> It appears trying to pack via <code>.csproj</code> has a share of problems, more at <a href="https://github.com/NuGet/Home/issues/2372" rel="noreferrer">https://github.com/NuGet/Home/issues/2372</a>.</p>
  
  <p><strong>edit 3:</strong> In VS 2017 it appears the <code>Package</code> tab is the best way to go to add the details. Then the <code>.csproj</code> needs to be modified like</p>
  
  <pre><code>&lt;PropertyGroup&gt;
    &lt;TargetFramework&gt;netstandard2.0&lt;/TargetFramework&gt;
    &lt;RuntimeIdentifiers&gt;win-x64;debian-x64&lt;/RuntimeIdentifiers&gt;
  &lt;/PropertyGroup&gt;
  
  &lt;ItemGroup&gt;
    &lt;Content Include="lib\runtimes\win-x64\native\.exe"&gt;
      &lt;PackagePath&gt;lib/runtimes/win-x64/native/.exe&lt;/PackagePath&gt;
      &lt;Pack&gt;true&lt;/Pack&gt;
      &lt;CopyToOutputDirectory&gt;PreserveNewest&lt;/CopyToOutputDirectory&gt;
    &lt;/Content&gt;
  &lt;/ItemGroup&gt;
  </code></pre>
  
  <p>The native resource is included in the NuGet package, but not restored properly.</p>
  
  <p><strong>edit 4:</strong> Other people have similar issues. Further links and rationale at <a href="https://github.com/NuGet/Home/issues/6645" rel="noreferrer">https://github.com/NuGet/Home/issues/6645</a>.</p>
  
  <p><strong>edit 5:</strong> With the aforementioned structure, one last thing needed to add is a file as follows to the root of <code>lib</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;ItemGroup&gt;
      &lt;Content Include="$(MSBuildThisFileDirectory)../../lib/runtimes/win-x64/native/.exe"&gt;
        &lt;CopyToOutputDirectory&gt;PreserveNewest&lt;/CopyToOutputDirectory&gt;
        &lt;Link&gt;.exe&lt;/Link&gt;
        &lt;Visible&gt;false&lt;/Visible&gt;
      &lt;/Content&gt;
    &lt;/ItemGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>and then to <code>Project.csproj</code> inside the <code>ItemGroup</code> add</p>
  
  <pre><code>&lt;Content Include="lib/{your_libraryname}.targets"&gt;
    &lt;PackagePath&gt;build/netstandard2.0/&lt;/PackagePath&gt;
    &lt;Pack&gt;true&lt;/Pack&gt;
  &lt;/Content&gt;
  </code></pre>
  
  <p>With these, this looks like being solved.</p>