ASP.NET Core Web API - 如何解决在依赖限制之外检测到的软件包版本问题

5
在我的ASP.NET Core-6 Web API中,当我尝试安装以下NuGet包时:

Install-Package AutoMapper.Extensions.Microsoft.DependencyInjection -Version 11.0.0

我收到了这个错误:

Detected package version outside of dependency constraint: Duende.IdentityServer.EntityFramework.Storage 5.2.0 requires AutoMapper (>= 10.0.0 && < 11.0.0) but version AutoMapper 11.0.1 was resolved.

在尝试解决这个问题时,我安装了AutoMapper ver-11.0.1。
然后应用程序标记了已安装的AutoMapper。
如何解决这个错误?
谢谢。

安装最新版本的Automapper。 - Kiran Joshi
@KiranJoshi - 这就是我所做的导致错误的原因。我的意思是最新的automapper。 - Ayobamilaye
更新(或添加明确引用)支持AutoMapper版本11+的Duende.IdentityServer.EntityFramework.Storage NuGet包的版本。 - Martin Costello
1个回答

9

TLDR: 将AutoMapper.Extensions.Microsoft.DependencyInjection降级到8.1.1,该版本依赖于AutoMapper (>= 10.1.1 && < 11.0.0)

https://www.nuget.org/packages/AutoMapper.Extensions.Microsoft.DependencyInjection/8.1.1

长答案:

我也遇到了类似的警告或错误,但是在安装NuGet AutoMapper时出现了问题:

NU1608检测到包版本超出依赖约束: Duende.IdentityServer.EntityFramework.Storage 5.2.0需要 AutoMapper (>= 10.0.0 && < 11.0.0),但已解析版本为AutoMapper 11.0.1。

你可能已经安装了NuGet Microsoft.AspNetCore.ApiAuthorization.IdentityServer或类似的程序包。

https://www.nuget.org/packages/Microsoft.AspNetCore.ApiAuthorization.IdentityServer

如果您查看Microsoft.AspNetCore.ApiAuthorization.IdentityServer NuGet依赖项,您将看到:
  • net6.0
  • Duende.IdentityServer (>= 5.2.0)
  • Duende.IdentityServer.AspNetIdentity (>= 5.2.0)
  • Duende.IdentityServer.EntityFramework (>= 5.2.0)
  • Duende.IdentityServer.EntityFramework.Storage (>= 5.2.0)
  • Duende.IdentityServer.Storage (>= 5.2.0)
  • Microsoft.AspNetCore.Authentication.JwtBearer (>= 6.0.5)
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore (>= 6.0.5)
  • Microsoft.AspNetCore.Identity.UI (>= 6.0.5)
  • Microsoft.Extensions.Http (>= 6.0.0)
  • Newtonsoft.Json (>= 13.0.1)
您可以通过手动更新以下库来解决它:
  • Duende.IdentityServer
  • Duende.IdentityServer.AspNetIdentity
  • Duende.IdentityServer.EntityFramework
  • Duende.IdentityServer.EntityFramework.Storage
  • Duende.IdentityServer.Storage
Duende.IdentityServer.EntityFramework.Storage 6.1.0 依赖以下内容,可修复您的错误:
  • net6.0
  • AutoMapper (>= 11.0.0 && < 12.0.0)
  • Duende.IdentityServer.Storage (>= 6.1.0)
  • Microsoft.EntityFrameworkCore.Relational (>= 6.0.0)

https://www.nuget.org/packages/Duende.IdentityServer.EntityFramework.Storage/

然而,运行代码时使用endpoints.MapRazorPages();可能会导致以下异常:

System.Reflection.ReflectionTypeLoadException:“无法加载所请求的一个或多个类型。程序集'Microsoft.AspNetCore.ApiAuthorization.IdentityServer, Version=6.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'中类型'Microsoft.AspNetCore.ApiAuthorization.IdentityServer.ApiAuthorizationDbContext`1'的方法'get_ServerSideSessions'没有实现。”

我已经向Microsoft提出请求,要求他们更新Microsoft.AspNetCore.ApiAuthorization.IdentityServer以与最新的Duende.IdentityServer.EntityFramework.Storage兼容,这将解决问题。

https://github.com/dotnet/aspnetcore/issues/41897


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接