Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Consumer of NuGet package with Project Reference does not resolve dependencies of the referenced project

$
0
0

So, I have this NuGet package I want to create, called MainNugetPkg.

Inside my solution, there's another project called OtherProj.

Each of them has its own package dependencies/references (used to exemplify):

  • MainNugetPkg
    • System.Linq.Async
  • OtherProj
    • Enums.NET

Overall, I created a Console Application to test at runtime, called Pruebitas, which only has a PackageReference to MainNugetPkg.Here's a screenshot of the solution tree:Solution tree

I managed to make MainNugetPkg expose the classes defined in OtherProj (just SomeDto in this case) when the package is generated, but the dependencies of OtherProj itself are not being included (i.e. Enums.NET), so when Pruebitas.Program.Main is ran, I get the following exception:

First, the 'Program.cs' file:

using MainNugetPkg;var srv = new MainService();var ct = srv.GetEmpty() // Calls 'AsyncEnumerable.Empty<int>()'    .ToBlockingEnumerable()    .ToList();Console.WriteLine(ct.Count); // Should write "0"var result = srv.GetNew(MainEnum.One);Console.WriteLine(result.Desc); // Should write "One"

Now the exception:

System.IO.FileNotFoundException  HResult=0x80070002  Mensaje = Could not load file or assembly 'Enums.NET, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7ea1c1650d506225'. El sistema no puede encontrar el archivo especificado.  Origen = OtherProj  Seguimiento de la pila:   en OtherProj.SomeDto`1.get_Desc()   en Program.<Main>$(String[] args) en C:\Users\<user>\source\repos\Pruebitas\Pruebitas\Program.cs: línea 11

Now, the MainNugetPkg's .csproj contains the following:

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net8.0</TargetFramework><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><GeneratePackageOnBuild>true</GeneratePackageOnBuild><RestoreProjectStyle>PackageReference</RestoreProjectStyle></PropertyGroup><ItemGroup><PackageReference Include="System.Linq.Async" Version="6.0.1" /></ItemGroup><ItemGroup><ProjectReference Include="..\OtherProj\OtherProj.csproj"><PrivateAssets>all</PrivateAssets></ProjectReference></ItemGroup><PropertyGroup><TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetMyPackageFiles</TargetsForTfmSpecificBuildOutput></PropertyGroup><Target Name="GetMyPackageFiles"><ItemGroup><BuildOutputInPackage Include="$(OutputPath)OtherProj.dll"><PackagePath>lib\$(TargetFramework)\</PackagePath></BuildOutputInPackage></ItemGroup></Target></Project>

NOTES:

  • OtherProj.SomeDto.Desc calls a EnumsNET extension (AsString)
  • I also tried removing the PrivateAssets tag from the provided .csproj, and it results in Pruebitas throwing the error: NU1101 saying OtherProj could not be found.

Question is: how should the .csproj files be configured so that MainNugetPkg includes every recursive dependency down its tree?


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>