title: How to add a .targets file into a Nuget package automatically after every build?
body: <p>I'm extremely new to concepts like msbuild, nuget packages and .targets files, so please bear with me :)</p>
  <p>I have a C# project which is supposed to generate a Nuget package which contains a native DLL. I'm able to get this working, but when I install that Nuget package in another C# project, the native DLLs are not copied over. For this issue, this question seems to be helpful:</p>
  <p><a href="https://stackoverflow.com/questions/19478775/add-native-files-from-nuget-package-to-project-output-directory">Add native files from NuGet package to project output directory</a></p>
  <p>However all the solutions there mention adding a .targets file into the build folder inside the nuget package. <strong>But how do I do this ??? In other words, where do I place this .targets file in my source code, such that when the project is built and the nuget package is generated, the .targets file is added into the nuget package (under 'build' folder) ??</strong></p>
  <p>This is the current contents of the nuget package that's generated on every build (notice that there's no .targets file):</p>
  <pre><code>root
  |   Com.CompanyName.Sdk.nuspec
  |   [Content_Types].xml
  |
  +---lib
  |   +---native
  |   |       Com.CompanyName.Hashing.dll
  |   |
  |   \---netcoreapp3.1
  |           Com.CompanyName.Sdk.dll
  |           Com.CompanyName.Core.dll
  |
  +---package
  |   \---services
  |       \---metadata
  |           \---core-properties
  |                   b2b8c6e91425459ba050043277f18f48.psmdcp
  |
  \---_rels
          .rels
  </code></pre>
  <p>I assumed I might have to place the .targets file in the same location as the CSPROJ file, so currently it's located at the root directory of the project where the CSPROJ is also located.</p>
  <p>This is the contents of my NUSPEC file, which is also in the root directory of the project:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;package&gt;
    &lt;metadata&gt;
      .....some metadata here.....
      &lt;dependencies&gt;
        &lt;group targetFramework=&quot;netcoreapp3.1&quot;&gt;&lt;/group&gt;
        &lt;group targetFramework=&quot;native&quot;&gt;&lt;/group&gt;
      &lt;/dependencies&gt;
    &lt;/metadata&gt;
    &lt;files&gt;
      &lt;file src=&quot;Com.CompanyName.Sdk.dll&quot; target=&quot;lib\netcoreapp3.1&quot; /&gt;
      &lt;file src=&quot;Com.CompanyName.Core.dll&quot; target=&quot;lib\netcoreapp3.1&quot; /&gt;
      &lt;file src=&quot;Com.CompanyName.Hashing.dll&quot; target=&quot;lib\native&quot; /&gt;
    &lt;/files&gt;
  &lt;/package&gt;
  </code></pre>
  <p>Also, if the add the following import in the NUSPEC at the bottom with the other imports ...</p>
  <pre><code>&lt;file src=&quot;Com.CompanyName.Sdk.targets&quot; target=&quot;build\Com.CompanyName.Sdk.targets.targets&quot; /&gt;
  </code></pre>
  <p>... I get an msbuild error that the .targets file isn't found:</p>
  <pre><code>C:\Program Files\dotnet\sdk\5.0.408\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5019: File not found: 'Microso
         ft.Com.CompanyName.Sdk.targets'. [C:\git\sdk\sources\dev\Sdk\Com.CompanyName.Sdk.csproj]
  </code></pre>
  <p>So how do I fix this ??</p>