19

Just as the question says really, how can I pack multiple projects / assemblies using dotnet pack?

Using VS2017 with new csproj files.

Matt Whetton
  • 6,616
  • 5
  • 36
  • 57

2 Answers2

31

Include assemblies what you need in csproj file

  <ItemGroup>
    <Content Include="bin\Release\net46\Newtonsoft.Json.dll">
      <PackagePath>lib\net46\</PackagePath>
      <Pack>true</Pack>
    </Content>
  </ItemGroup>

also if you want to include assembly from your solution you can do this in the same way, but to exclude dependency to another nuget package use PrivateAssets tag

  <ItemGroup>
    <Content Include="bin\Release\net46\My.Contracts.dll">
      <PackagePath>lib\net46\</PackagePath>
      <Pack>true</Pack>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="My.Contracts.csproj">
      <PrivateAssets>all</PrivateAssets>
    </ProjectReference>
  </ItemGroup>
Dumitru
  • 833
  • 3
  • 12
  • 26
  • 12
    Thanks a lot - this also worked for me. The path can be a bit more generic: ` lib\$(TargetFramework)\ true ` – Volker von Einem Jun 19 '18 at 09:37
  • In my case it was required to add `true` child to the `Content` element – oleksa Sep 17 '19 at 07:28
  • 2
    @VolkervonEinem the path can be even more generic using the `OutDir` variable `lib\$(TargetFramework)` – oleksa Sep 18 '20 at 13:11
  • @oleksa both things did unfortunately not work for me. using OutDir threw me an error of not being able to find a DLL. using TargetFramework put my dll directlry into lib – rominator007 Feb 16 '22 at 20:24
8

I've looked into doing this in depth, and the only way I got things working was to make my own nuspec file. I used dotnet build -C release to build the individual projects, and I used my nuspec file to pull in the multiple assemblies into the 1 package.

Unfortunately it seems, the big idea with dotnet pack was to associate each project with a separate dll. If you have multiple projects, the idea was to pack each project, and still rely on package references.

TerribleDev
  • 2,195
  • 1
  • 19
  • 31