简体   繁体   English

在不同的 netstandard2.0 库 NU1202 中安装 netstandard2.0 Nuget 包

[英]Installing a netstandard2.0 Nuget Package inside a different netstandard2.0 library NU1202

I'm currently struggling with something that seems like it's simple, but I can't track down anyone with a similar issue.我目前正在为一些看起来很简单的事情而苦苦挣扎,但我无法找到任何有类似问题的人。

I'm converting some libraries to netStandard and one depends on another.我正在将一些库转换为 netStandard,一个依赖于另一个。 We'll call them A and B.我们称它们为 A 和 B。

A is compiling fine as a netStandard2.0 library, built with the 3.1 SDK according to dotnet --version in the directory. A 正在编译为 netStandard2.0 库,根据目录中的 dotnet --version 使用 3.1 SDK 构建。 The nupkg is built in the Release folder and I move it to a local package source to test on my box. nupkg 内置在 Release 文件夹中,我将其移动到本地包源以在我的盒子上进行测试。

B is a netStandard2.0 class library as well. B 也是一个 netStandard2.0 类库。 It requires A, but navigating to my nupkg for A inside of NuGet Package Manager for B and clicking install generates a curious error.它需要 A,但是在 NuGet Package Manager for B 中导航到我的 nupkg for A 并单击安装会生成一个奇怪的错误。

NU1202 A is not compatible with netStandard2.0, Package A supports: netcoreapp2.1 NU1202 A 不兼容 netStandard2.0,Package A 支持:netcoreapp2.1

A is a netStandard library. A 是一个 netStandard 库。 B is a netStandard library. B 是一个 netStandard 库。

When I look at the A.csproj file in the tag I'm seeing:当我查看标签中的 A.csproj 文件时,我看到:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Description>The initial .net standard 2.0 offering of A</Description>
  </PropertyGroup>
</Project>

So it seems to be targeting for a netStandard2.0 (which includes netFramework 4.6.1 to netCore 2.2?)所以它似乎是针对 netStandard2.0(包括 netFramework 4.6.1 到 netCore 2.2?)

Am I missing something simple?我错过了一些简单的东西吗?

After googling around with nu1202 and netStandard2.0 - which mostly came up with a scenario of A being a library and B being an application, not a B being a library like my situation - I present:在使用 nu1202 和 netStandard2.0 进行谷歌搜索后——主要是想出了一个场景,A 是一个库,B 是一个应用程序,而不是像我的情况 B 是一个库——我提出:

Things I've Tried Based on Dissimilar Problems我基于不同问题尝试过的事情

  1. Confirm the dotnet --version of each of the A / B projects, both at 3.1.402确认每个 A/B 项目的 dotnet --version,都在 3.1.402
  2. Confirmed my Nuget Package Mangaer version is fairly recent / up to date: 5.7.0确认我的 Nuget Package Mangaer 版本相当新/最新:5.7.0
  3. Attempted to use the Package Manager Console to the exact same result.尝试使用包管理器控制台获得完全相同的结果。
  4. Cleaned and Rebuilt / Packed the A.csproj清理和重建/打包 A.csproj
  5. Tried including the A.nuspec file in the Package Source folder with A.nupkg尝试使用 A.nupkg 在 Package Source 文件夹中包含 A.nuspec 文件
  6. Pulled the A.csproj manually into the project to confirm it could be added as a Project Reference which worked, but isn't how I want to solve this problem.将 A.csproj 手动拉入项目以确认它可以添加为有效的项目参考,但这不是我想要解决这个问题的方式。

I've maybe tried more but at this point, maybe the question I should be asking is: Is it possible to reference netStandard libraries inside of other netStandard libraries?我可能已经尝试了更多,但在这一点上,也许我应该问的问题是:是否可以在其他 netStandard 库中引用 netStandard 库?

What am I missing?我错过了什么?

I believe, in the end, that this might be an issue with the Pack/Build (with Generate Package on Build) functionality in VS.我相信,最后,这可能是 VS 中的 Pack/Build(在构建时生成包)功能的问题。

I am able to manually create the package of the A library inside of Nuget Package Explorer, that package will import into B just fine.我可以在 Nuget Package Explorer 中手动创建 A 库的包,该包将导入到 B 中就好了。

I followed this resource , but was never able to build the package using Visual Studio, which makes it difficult to modify the version of Nuget Package Manger nowadays since it's bundled in. I'm at version 5.7, it may be that 5.6 would work as that's listed as the latest Stable release on google, but either way - for now, I believe I'll just manually make my packages instead of trying to auto-generate them.我关注了这个资源,但是从来没有能够使用 Visual Studio 构建包,这使得现在很难修改 Nuget Package Manger 的版本,因为它是捆绑的。我在 5.7 版,可能 5.6 可以作为这在谷歌上被列为最新的稳定版本,但无论哪种方式 - 现在,我相信我只会手动制作我的包,而不是尝试自动生成它们。

If anyone has a better solution or thoughts about how to troubleshoot this, I am all ears.如果有人对如何解决此问题有更好的解决方案或想法,我会全力以赴。


EDIT编辑


It turns out, the auto package build feature DOES work.事实证明,自动包构建功能确实有效。

What happened in the end: I commandeered some old .net Core library titles, to downshift them to .net Standard instead of keeping 2 parallel copies.最后发生了什么:我征用了一些旧的 .net Core 库标题,将它们降级到 .net Standard 而不是保留 2 个并行副本。

There was already a .net core version of A.1.0.0.nupkg and a B.1.0.1.nupkg, but in a different nuget package source.已经有 A.1.0.0.nupkg 和 B.1.0.1.nupkg 的 .net 核心版本,但在不同的 nuget 包源中。

When I build a NEW .net Standard A.1.0.0.nupkg and put it in a local source, somehow even when pointing to that local source, nuget tried to install the .net core from ... i guess a cached copy of the production nuget package source (I cleared caches like 50 times so I don't know how nuget is getting these wires crossed).当我构建一个新的 .net 标准 A.1.0.0.nupkg 并将其放在本地源中时,即使指向该本地源,nuget 也尝试安装 .net 核心...我猜是缓存的副本生产 nuget 包源(我清除了 50 次左右的缓存,所以我不知道 nuget 是如何让这些电线交叉的)。

Easily replicatable by making a version .net Standard A.1.0.1.nupkg, it imports fine because there was no .net core A.1.0.1.nupkg.通过制作 .net 标准版 A.1.0.1.nupkg 可以轻松复制,它可以很好地导入,因为没有 .net 核心 A.1.0.1.nupkg。 You can then rename that package and reversion it in Nuget Package Explorer, but not change the contents, and it will fail.然后,您可以重命名该包并在 Nuget 包资源管理器中将其还原,但不能更改内容,否则会失败。 This was confirmed when I had to stair step my versioning of the .net Standard version of B.nupkg from 1.0.0 to 1.0.2 thus going further than the .net Core version of B.nupkg.当我不得不将 B.nupkg 的 .net Standard 版本的版本控制从 1.0.0 升级到 1.0.2 从而比 B.nupkg 的 .net Core 版本更进一步时,这一点得到了证实。

So in the end, the auto package functionality isn't broken (thankfully).所以最后,自动打包功能没有被破坏(谢天谢地)。 The Nuget Package Explorer manual creation fixed my problem because I ticked up the version when I manually made it. Nuget Package Explorer 手动创建解决了我的问题,因为我在手动创建时勾选了版本。

I would never have expected the production library package source to interfere with a local package folder...我从没想过生产库包源会干扰本地包文件夹......

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

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