TODAY I LEARNED

How to use Project-to-Project references in nuget packages with .NET Core CLI SDK

Mon Sep 16, 2019

Out of the box the dotnet pack command (from the .Net Core CLI) treat every project in the Visual Studio solution as its own Nuget package.

Project-to-project references aren’t packaged inside the project. Currently, you must have a package per project if you have project-to-project dependencies.
-.NET Core CLI Docs https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-pack

Today i learned that if you add PrivateAssets=“all” to the ProjectReferece in the .csproj file, these project will be included in the Nuget package, instead of marked as a dependency.

1
2
3
<ItemGroup>
  <ProjectReference Include="Dependency.csproj" PrivateAssets="all" />
</ItemGroup>

This only works for .NET Core or .NET Standard build with the .NET Core CLI and not .Net Framework build with MSBuild.