简体   繁体   English

nuget 没有使用 nuget package for Microsoft.Extensions.Logging 中指定的内容解决依赖关系

[英]nuget not resolving dependency using what specified in nuget package for Microsoft.Extensions.Logging

Background:背景:

I have created a class library for .net core (targetting v2.2 ), and I have a .net core application as well (targetting v2.2 ).我已经为 .net 核心(针对v2.2 )创建了一个 class 库,并且我也有一个 .net 核心应用程序(针对v2.2

I am trying to export the library as nuget package and install it in my application.我正在尝试将库导出为 nuget package 并将其安装在我的应用程序中。 Here is the dependencies for my library这是我的库的依赖项

MyLib 依赖项

I am able to export it as nuget package and for now I am storing it in local nuget repo.我可以将它导出为 nuget package 并且现在我将它存储在本地 nuget 存储库中。 But when I try to install this library package in my application it's not getting installed due to package version conflict for Microsoft.Extensions.Logging .但是,当我尝试在我的应用程序中安装这个库 package 时,由于Microsoft.Extensions.Logging的 package 版本冲突,它没有安装。 Here's package manager console output.这里是 package 经理控制台 output。

包管理器控制台输出

Issue:问题:

I have specified the exact version for Microsoft.Extensions.Logging ie [2.2.0] as we could confirm that in the screenshot showing dependency for my library, then why it's getting resolved to version 3.0.0 ?我已经为Microsoft.Extensions.Logging指定了确切的版本,即[2.2.0] ,因为我们可以在显示我的库的依赖关系的屏幕截图中确认这一点,那么为什么它会被解析为3.0.0版本? How could I resolve this issue?我该如何解决这个问题?

Details about the environment:关于环境的详细信息:

  • NuGet product used (Package Manager Console): Package Manager Console Host Version 5.3.1.6268使用的 NuGet 产品(包管理器控制台):Package 管理器控制台主机版本5.3.1.6268
  • VS version (if appropriate): Microsoft Visual Studio Community 2019 Version 16.3.8 VS 版本(如果适用):Microsoft Visual Studio Community 2019 Version 16.3.8
  • OS version (ie win10 v1607 (14393.321)): Windows 10 Enterprise Version: 1809操作系统版本(即win10 v1607(14393.321)):Windows 10企业版: 1809

How could I resolve this issue?我该如何解决这个问题?

To resolve the strange behavior in your side, you should clean the nuget cache before installing that package in your current project.要解决您这边的奇怪行为,您应该在当前项目中安装 package 之前清理 nuget 缓存

(To make sure the cache is cleaned up, I suggest you go %userprofile%\.nuget\packages to check if there exists Com.lib folder within the Packages folder) (为了确保清理缓存,我建议您 go %userprofile%\.nuget\packages检查Packages文件夹中是否存在Com.lib文件夹)

I have specified the exact version for Microsoft.Extensions.Logging ie [2.2.0] as we could confirm that in the screenshot showing dependency for my library, then why it's getting resolved to version 3.0.0?我已经为 Microsoft.Extensions.Logging 指定了确切的版本,即 [2.2.0],因为我们可以在显示我的库的依赖项的屏幕截图中确认这一点,那么为什么它会被解析为 3.0.0 版本?

I think the one(Com.Mylib) you want to install is not the first one you pack.我认为您要安装的(Com.Mylib)不是您打包的第一个。 I mean that you may actually build and pack several different Com.Mylib package with different content.我的意思是您实际上可能会构建和打包几个不同的 Com.Mylib package 具有不同的内容。 And all of their names is Com.lib.1.0.0.nupkg .他们所有的名字都是Com.lib.1.0.0.nupkg

Nuget stores all nuget cache in %userprofile%\.nuget\packages . Nuget 将所有 nuget 缓存存储在%userprofile%\.nuget\packages中。 So if I once install one PackageA in any project.因此,如果我曾经在任何项目中安装一个 PackageA。 The cache of PackageA is stored there. PackageA 的缓存存储在那里。 And if I open a new project trying to install the PackageA with same version(1.0.0), it actually installs the one from cache.如果我打开一个新项目尝试安装具有相同版本(1.0.0)的 PackageA,它实际上会从缓存中安装一个。 So we will meet this strange behavior:所以我们会遇到这种奇怪的行为:

在此处输入图像描述

Nuget can recognize the Com.lib package depends on other 2.2.0 packages. Nuget 可以识别 Com.lib package 依赖于其他 2.2.0 包。 But when it tries to install that package, it finds the package has existed in cache.但是当它尝试安装 package 时,它发现 package 已经存在于缓存中。 Then he tries to install the one from cache, and I guess content of the one in cache is different from your latest one, then the issue occurs.然后他尝试从缓存中安装一个,我猜缓存中的内容与您最新的内容不同,然后出现问题。

Suggestions:建议:

1.When developing locally, use project reference instead of Nuget packages. 1.本地开发时,使用工程参考代替Nuget包。

2.If you need to test the nuget package every time after packing, please make sure the package version has increased.(1.0.0=>1.0.1=>1.0.3... or beta-1.0.12, preview-xxx) 2.If you need to test the nuget package every time after packing, please make sure the package version has increased.(1.0.0=>1.0.1=>1.0.3... or beta-1.0.12, preview- xxx)

3.If you have special reason do use same version 1.0.0, please clean the cache to avoid previous cache affects current project. 3.如果您有特殊原因使用相同的1.0.0版本,请clean the cache缓存影响当前项目。

Hope all above helps:)希望以上所有帮助:)

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

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