Home: Include transitive PackageReference dependencies from ProjectReference

Created on 28 Oct 2019  路  3Comments  路  Source: NuGet/Home

Details about Problem

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe):
dotnet.exe

dotnet.exe --version (if appropriate):
3.0.100

OS version (i.e. win10 v1607 (14393.321)):
Microsoft Windows [Version 10.0.18362.418]

Detailed repro steps so we can see the same problem

  1. Create a solution with two projects called e.g. Test.Lib and Test.Package. Use the Microsoft.NET.Sdk csproj style

  2. In Test.Lib include:

<PropertyGroup>
  <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
  <IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
    <PackageReference Include="Any_Nuget_Package" Version="..." />
</ItemGroup>
  1. In Test.Package include:
<PropertyGroup>
  <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
  <ProjectReference Include="..\Test.Lib\Test.Lib.csproj" />
</ItemGroup>
  1. Run dotnet restore and dotnet build generating Test.Package.nupkg

Expected behaviour: Test.Package.nupkg contains Test.package.nuspec with Any_Nuget_Package as dependency

Actual behaviour: Test.Package.nupkg contains Test.package.nuspec, but Any_Nuget_Package is not a dependency.

This results in the consumer of Test.Package.nupkg not knowing about the necessary dependency and resulting in a build with missing dll.

I fully expect it might be an user error, but I'd appreciate support.

Pack dotnet.exe Duplicate

Most helpful comment

It seems that this issue is a duplicate of #3891

If that's the case, a possible workaround is documented here: #3891 (comment)

Let us know if you have any questions.

Hi @dominoFire

I have seen it and used it to solve another problem (How to get the Test.Lib.dll into the Test.Package.nupkg).

This is however about including an entry in the generated nuspec's <dependencies> for the <ProjectReference>'s dependencies.

I can think of a workaround, where I create the <ItemGroup> with dependencies and include it in both Test.Lib and Test.Package, therefore I do not risk de-syncing them, however I'd still rather have an automated solution.

To phrase the issue differently: "How to copy the <ProjectReference>'s <PackageReference>s into the consuming/parent project."

All 3 comments

It seems that this issue is a duplicate of https://github.com/nuget/home/issues/3891

If that's the case, a possible workaround is documented here: https://github.com/nuget/home/issues/3891#issuecomment-377319939

Let us know if you have any questions.

It seems that this issue is a duplicate of #3891

If that's the case, a possible workaround is documented here: #3891 (comment)

Let us know if you have any questions.

Hi @dominoFire

I have seen it and used it to solve another problem (How to get the Test.Lib.dll into the Test.Package.nupkg).

This is however about including an entry in the generated nuspec's <dependencies> for the <ProjectReference>'s dependencies.

I can think of a workaround, where I create the <ItemGroup> with dependencies and include it in both Test.Lib and Test.Package, therefore I do not risk de-syncing them, however I'd still rather have an automated solution.

To phrase the issue differently: "How to copy the <ProjectReference>'s <PackageReference>s into the consuming/parent project."

My problem is exactly what @p-kaczynski describes. As he states, this is not a duplicate. Is there any recommended workaround for this, or plans to address it directly?

Was this page helpful?
0 / 5 - 0 ratings