简体   繁体   中英

Nuget package dependencies issue

I have a project Customer.Invoices that is a nuget package the csproj file has the following below. The PackageReference Customer.Prices is a nuget package referenced within the Customer.Invoices project.

The Customer.Groups project reference is just a referenced project within the Customer.Invoices solution.

<ItemGroup>
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.4" />
    <PackageReference Include="Customer.Prices" Version="1.0.0.14" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\CustomerGroups\CustomerGroups.csproj" />
  </ItemGroup>

I now am using the Customer.Invoices nuget package which is the main package I need in another C# project. I am running into two issues:

1.) if I don't also add the Customer.Prices nuget package it says it can't find the assembly when running a method in the Customer.Invoices project.

2.) I am getting an assembly not found for the CustomerGroups project.

How do I resolve these issues as I know there are include assets etc. but not sure how to handle the dependencies. For the second issue not sure if this would work is adding privateassets=all to the project reference like so as this is a.Net Core 2.2 project:

<ProjectReference PrivateAssets="all" Include="..\CustomerGroups\CustomerGroups.csproj" />

Again not sure that is correct as I don't quite understand yet the assets but also need to figure out can I have the Customer.Prices assembly working without also having to add that nuget package.

Thanks for any help

Both isses are related to how packages are built and resolved. Suppose you have projects A and B and A references B . A references a package called A-Package . B references a package called B-Package .

Old Project Format

In an old-style project (prior to SDK-Style Format) the output of a project after building will contain only libraries and contents of direct dependencies. Here, the output folder of A will contain files from A , B and A-Package , while the output folder of B will contain files from B and B-Package . This will happen with packages.config and PackageReference as well.

SDK Project Format

The SDK project format with PackageReference (which is the default for .NET Core) supports transitive dependencies . This is described in detail here . This means if A references B and B references a package B-Package , then A will also get the contents of B-Package . As for the example above, the output folder of A will contain files from A , B , A-Package and also B-Package .

So the issue in question 1 is most probably the result of using the wrong framework, or not using the SDK-Style format with PackageReference .

Project References

The second issue is that project references are not copied to your package. This is why the assemblies are not found. At the moment this is not supported, but there are workarounds . PrivateAssets , IncludeAssets and similar attributes will not help here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM