Search code examples
nugetnuget-packagedotnet-core-pack

Creating and installing a nuget package with referenced project


I want to publish a dotnetcore2.1 nuget package using dotnet pack and dotnet nuget push.

The package is a project in a solution that has a reference to another project in that solution.

I can't install the package because it can't resolve the referenced project.

I tried doing this, and it includes the referenced package .dll to the .nupkg file, but it's still not possible to install it.

I can't really figure out what is the 'expected' way to do this. I definitely don't intend to publish the referenced project to the nuget feed.

Is this a massive oversight by microsoft or am I not getting something?


Solution

  • You have a project A that you want to pack and this project references another project B that is not usable or not intended for use on its own, but from a design perspective it is reasonable to keep it separate for purposes like reuse. In the end the package for project A should also contain project B.

    Indeed this is an issue tracked in the NuGet repository, issue 3891. In both this and your link to the corresponding .NET project issue there are some workaround involving MS Build, but there is no official support, yet.

    As stated in the above issue, even Microsoft seems to be aware of this issue and simply creates packages for the referenced projects that are marked with

    Please do not reference directly

    I think that until project references are supported, the safest way is to do same, although it is not convenient. Workarounds may become obsolete or cause strange behavior. However, since your referenced project is only intended to be used in your main library, you could include it like this

    <PackageReference Include="LLL.Client" Version="1.0.0" PrivateAssets="all"/>
    

    This way, the package contents from your referenced project will only be included in your project and consumers of your main package will not be able to see them.