title: Add dependencies of reference projects to NuGet package
body: <p>I'm using <code>dotnet pack</code> command for creating a NuGet package for the following scenario:</p>
  <p>The projects structure:</p>
  <pre><code>Project B
  |----&gt; Project A
  
  Project A
  |----&gt; SomePackage
  </code></pre>
  <p>I want to create a single NuGet package the contains <code>ProjectB.dll</code>, <code>ProjectA.dll</code>, and <code>SomePackage</code> as NuGet package dependency.</p>
  <p>In order to include <code>ProjectA.dll</code> as part of the NuGet package (and not package dependency), I used the following solution that suggests <a href="https://stackoverflow.com/a/59893520/7122901">here</a>.</p>
  <p>In <code>ProjectB.csproj</code>:</p>
  <pre><code>  &lt;ProjectReference Include=&quot;ProjectA.csproj&quot; PrivateAssets=&quot;all&quot;/&gt;
  
    &lt;PropertyGroup&gt;
      &lt;TargetsForTfmSpecificBuildOutput&gt;$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage&lt;/TargetsForTfmSpecificBuildOutput&gt;
    &lt;/PropertyGroup&gt;
    
    &lt;Target Name=&quot;CopyProjectReferencesToPackage&quot; DependsOnTargets=&quot;BuildOnlySettings;ResolveReferences&quot;&gt;
      &lt;ItemGroup&gt;
        &lt;!-- Filter out unnecessary files --&gt;
        &lt;_ReferenceCopyLocalPaths Include=&quot;@(ReferenceCopyLocalPaths-&gt;WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')-&gt;WithMetadataValue('PrivateAssets', 'All'))&quot;/&gt;
      &lt;/ItemGroup&gt;
  
      &lt;!-- Print batches for debug purposes --&gt;
      &lt;Message Text=&quot;Batch for .nupkg: ReferenceCopyLocalPaths = @(_ReferenceCopyLocalPaths), ReferenceCopyLocalPaths.DestinationSubDirectory = %(_ReferenceCopyLocalPaths.DestinationSubDirectory) Filename = %(_ReferenceCopyLocalPaths.Filename) Extension = %(_ReferenceCopyLocalPaths.Extension)&quot; Importance=&quot;High&quot; Condition=&quot;'@(_ReferenceCopyLocalPaths)' != ''&quot; /&gt;
  
      &lt;ItemGroup&gt;
        &lt;!-- Add file to package with consideration of sub folder. If empty, the root folder is chosen. --&gt;
        &lt;BuildOutputInPackage Include=&quot;@(_ReferenceCopyLocalPaths)&quot; TargetPath=&quot;%(_ReferenceCopyLocalPaths.DestinationSubDirectory)&quot;/&gt;
      &lt;/ItemGroup&gt;
    &lt;/Target&gt;
  </code></pre>
  <p><strong>The issue:</strong></p>
  <p>When I run <code>dotnet pack ProjectB.csproj</code> I'm getting a single package the contains ProjectA.dll and Project B.dll, but <strong>without a dependency to <code>SomePackage</code></strong>.</p>
  <p><strong>The question:</strong>
  How do I add the dependency to <code>SomePackage</code> to <code>ProjectB</code> NuGet package?</p>
  <p><strong>Possible solutions:</strong></p>
  <ol>
  <li>Manually add a package reference from ProjectB to <code>SomePackage</code>.</li>
  <li>Create <code>ProjectB.nuspec</code> file and manually add the dependency to <code>SomePakcage</code>.</li>
  </ol>
  <p>The disadvantage of the 2 approaches: I will need to add the dependency for every NuGet package that <code>ProjectA</code> use, which is very easy to forget and breakable.</p>