How to include DLL from project reference in NuGet package

When you’re packing your NuGet packages with

and the Whatever project happens to reference another project, Whatever.Dependency.csproj (with the <ProjectReference ...> tag in Whatever.csproj), the default behavior is to treat the reference as if the referenced project was ALSO a NuGet package, in which case you would need to


This might be what you want – and if so, then there’s no problem, and you can stop reading now. πŸ™‚

But sometimes, it’s NOT what you want! Sometimes you want to reference the project and have its resulting DLL copied and INCLUDED in your NuGet package – if that’s the case, check this out πŸ‘‡

In the old days, you would carefully craft your nuspec to include the DLL from the referenced project in the /lib folder of the package. We could also do that today, but it would be much easier to leverage the brilliant work done by Teroneko in the Teronis.MSBuild.Packaging.ProjectBuildInPackage NuGet package.

Simply install the package into the project you are about to pack:

and then edit the csproj file (Whatever.csproj in this case) and add the PrivateAssets="all" attribute to the relevant tag:

and then you can

and the NuGet will contain both Whatever.dll and Whatever.Dependency.dll.

Neat! πŸ˜ƒ