简体   繁体   English

Nuget package 依赖问题

[英]Nuget package dependencies issue

I have a project Customer.Invoices that is a nuget package the csproj file has the following below.我有一个项目 Customer.Invoices,它是 nuget package,csproj 文件具有以下内容。 The PackageReference Customer.Prices is a nuget package referenced within the Customer.Invoices project. PackageReference Customer.Prices 是 Customer.Invoices 项目中引用的 nuget package。

The Customer.Groups project reference is just a referenced project within the Customer.Invoices solution. Customer.Groups 项目引用只是 Customer.Invoices 解决方案中的一个引用项目。

<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.我现在正在使用 Customer.Invoices nuget package,这是我在另一个 package 项目中需要的主要 package。 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. 1.)如果我不添加 Customer.Prices nuget package 它说它在 Customer.Invoices 项目中运行方法时找不到程序集。

2.) I am getting an assembly not found for the CustomerGroups project. 2.) 我得到一个未找到 CustomerGroups 项目的程序集。

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:对于第二个问题,不确定这是否可行,将 privateassets=all 添加到项目引用中,就像这是一个.Net Core 2.2 项目:

<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.再次不确定这是正确的,因为我还不太了解资产,但还需要弄清楚我是否可以让 Customer.Prices 组件正常工作,而不必添加 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 .假设您有项目AB以及A引用B A references a package called A-Package . A引用了一个名为A-Package的 package 。 B references a package called B-Package . B引用了一个名为B-Package的 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.在旧式项目(SDK 样式格式之前)中,构建后项目的 output 将仅包含库和直接依赖项的内容。 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 .在这里, A的 output 文件夹将包含来自ABA-Package的文件,而B的 output 文件夹将包含来自BB-Package文件。 This will happen with packages.config and PackageReference as well. packages.configPackageReference也会发生这种情况。

SDK Project Format SDK 项目格式

The SDK project format with PackageReference (which is the default for .NET Core) supports transitive dependencies .带有PackageReferenceSDK 项目格式(这是 .NET 核心的默认值)支持传递依赖 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 .这意味着如果A引用BB引用 package B-Package ,那么A也将获得B-Package的内容。 As for the example above, the output folder of A will contain files from A , B , A-Package and also B-Package .对于上面的示例, A的 output 文件夹将包含来自ABA-PackageB-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 .所以问题 1 中的问题很可能是使用错误框架的结果,或者没有使用带有PackageReference的 SDK 样式格式。

Project References项目参考

The second issue is that project references are not copied to your package.第二个问题是项目引用没有复制到您的 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. PrivateAssetsIncludeAssets和类似的属性在这里没有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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