I'm experimenting with creating a NuGet package. I can create a package from a stand-alone class library project and it works fine. However, I'm seeing an error when I try to create a package from a class library project that references another class library project in the same solution.
I'm trying to create a NuGet package from a .NET Core 3.1 class library project, MyPackage
, which references another .NET Core 3.1 class library project, ReferencedClassLibrary
, in the same solution.
When I pack the MyPackage
project (via Visual Studio Solution Explorer > right click the project file > Pack) a *.nupkg file is created in the bin\debug folder. If I copy that *.nupkg file to the local NuGet package source I set up for testing, I can install the package into another solution.
However, during install of that NuGet package into another solution an error message is displayed:
NU1101: Unable to find package ReferencedClassLibrary. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, NuGet Personal Package Source, nuget.org
where "NuGet Personal Package Source" is the name of my local package source.
How do I include ReferencedClassLibrary
as part of NuGet package MyPackage
? Do I need to use NuGet.exe to pack the project with its dependencies or is there a way to do it via Visual Studio?
If we assume that ReferencedClassLibrary
is <ProjectReference>
, then the expectation is that a ReferencedClassLibrary
will also be packaged as a nupkg, in a way that is available to the consumer - which will then resolve the transitive dependencies automatically. If you want to embed the additional dll in the same package, things get much more complicated, as that is not the "simple mode" way that is expected. At that point, you might be able to convince the .csproj to embed it, but you're more likely to end up having to write the nuspec by hand. Unless you welcome and embrace this, just ship ReferencedClassLibrary
as a nupkg.