I have a problem with making a package of a project with other project as a reference.
In a few words… We have a Net. Core WebAPI with an Onion Architecture. Where those layers are implemented as referenced projects like: core, domain, infrastructure, etc...
My objective is to make this whole application in a modular/plugin way. Where we can attach and detach functionality to this application via our NuGet packages.
Currently, I've encountered a problem, where I have some unresolved dependencies of this project. Let me explain in a more detailed way.
When I create this package of my WebApi with Visual Studio or with dotnet cli - I have an output like this.
As you can see, this new package now have a dependency of included projects as other NuGet Packages. Because I have these references in my project.
<ItemGroup>
<ProjectReference Include="..\MIT.Fwk.Application\MIT.Fwk.Application.csproj" />
<ProjectReference Include="..\MIT.Fwk.Core\MIT.Fwk.Core.csproj" />
<ProjectReference Include="..\MIT.Fwk.Infra.Identity\MIT.Fwk.Infra.Identity.csproj" />
<ProjectReference Include="..\MIT.Fwk.Infra.IoC\MIT.Fwk.Infra.IoC.csproj" />
<ProjectReference Include="..\MIT.Fwk.Libs\MIT.Fwk.Libs.csproj" />
<ProjectReference Include="..\MIT.Fwk.Licensing\MIT.Fwk.Licensing.csproj" />
</ItemGroup>
It is also oblivious that this won't work out, because if I will unpack this new package. I can find only one .dll inside ./lib/net6.0
I've managed to find a way to resolve these project dependencies with the nuget cli application.
When I create a package with
nuget pack <pathTo.csproj> -IncludeReferencedProjects
I managed to resolve these project dependencies.
Now this NuGet package size has increased by over 4 times. Thus, inside it's ./lib/net6.0 we can see something like following:
All the .dll's are there! Even when I try to install this package, I can see no other references inside of it.
But..... when I try to install this newly created package inside another empty project…
It goes to fetch all my NuGet sources and tries to find those MIT.Fwk.Application, MIT.Fwk.Core, MIT.Fwk.Infra.Identity, MIT.Fwk.Licensing NuGet packages…
When the timeout passes. It just says that this package cannot be installed because it couldn't find those packages, and that's all.
Why it doesn't use those .dll's which it has inside of it ? They are all there and ready to be used. But instead, it creates these "invisible" NuGet dependencies and requires all of those .dll's files which I've shown up before - as NuGet packages.
Is there a way to resolve this ?
Indeed, many are waiting for this to work - you can follow up on the GitHub issue here. On April 2022 the NuGet team showed intentions to make progress with this, but it wasn't included in their 2022 plan. Maybe in 2023 :)
To sum it up: referencing a NuGet package which itself have PackageReference
s - doesn't work as one might expect. As you experienced, the PackageReference
s are just not being included as dependencies of the referenced NuGet package.
The thing is, the referenced NuGet package (hereon: parent package) expects its own dependencies to also be NuGet packages (hereon: children packages). But even then, this won't be enough, because the parent NuGet package has no knowledge of the packed children packages - unless you explicitly let it know about them.
You have 3 options:
nuget pack
(or dotnet pack
) all of your PackageReference
s projects, and then have both the parent and children nupkg
files in the same place (e.g. copy the resulted children's nupkg
files into the parent package folder, by using a script as suggested here, by having a nuspec
file as suggested here)..csproj
of the parent NuGet package to include the children dlls inside the NuGet parent package - or install the Teronis package that will do it for you.