Matt Whetton
Matt Whetton

Reputation: 6786

Pack multiple assemblies with dotnet pack

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

Using VS2017 with new csproj files.

Upvotes: 21

Views: 11894

Answers (2)

Dumitru
Dumitru

Reputation: 863

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>

Upvotes: 31

TerribleDev
TerribleDev

Reputation: 2245

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.

Upvotes: 9

Related Questions