Schwammy
Schwammy

Reputation: 233

How to create Nuget package with nested dependencies

I'm working on a .NET Core solution. For one of the projects within the solution, I need to build a Nuget package.

Project A has a reference to another project B in the solution, set up as a project reference. Project B has a dependency on a Nuget package C.

Now, when I create a Nuget package for A, it includes A.dll and B.dll but not C.dll

Can someone help me figure this out? How can I include all 3 .dlls?

Thanks, Andy

Upvotes: 2

Views: 5046

Answers (2)

Rob Relyea
Rob Relyea

Reputation: 401

See https://github.com/NuGet/Home/issues/3891 for the feature request for dotnet.exe pack to the nuget client team. There are workarounds and debates in that issue.

Thx, Rob Relyea, NuGet Client Team

Upvotes: 0

Rockford Lhotka
Rockford Lhotka

Reputation: 714

You can certainly solve this by creating your own nuspec file. I am not sure how to do it within the context of the csproj file.

For example, with #csla we manage all our own nuspec files because there are so many moving parts.

Within a nuspec file you can list the specific files you want included, along with any package dependencies. So in your example it sounds like your nuspec would include the project A and B assemblies, so something like this:

<files>
  <file src="..\..\bin\Release\netstandard\netstandard2.1\**\A.dll" target="lib\netstandard2.1" />
  <file src="..\..\bin\Release\netstandard\netstandard2.1\**\B.dll" target="lib\netstandard2.1" />
</files>

And would declare the dependency to package C.

<dependencies>
  <group targetFramework="netstandard2.1">
    <dependency id="C" version="1.0.0" />
  </group>
</dependencies>

You can see numerous examples in the #csla repo. Perhaps the closest (not using wildcards) is the Csla.Blazor.nuspec file.

Upvotes: 4

Related Questions