问题
I am trying to install some packages in my API using :
Install-Package Microsoft.EntityFrameworkCore.SqlServer
It throws an Error (Given below ) :
NU1608: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.1.1 requires Microsoft.EntityFrameworkCore.SqlServer (>= 2.1.1 && < 2.2.0) but version Microsoft.EntityFrameworkCore.SqlServer 2.2.0 was resolved.
Install-Package : NU1107: Version conflict detected for
Microsoft.EntityFrameworkCore. Install/reference Microsoft.EntityFrameworkCore
2.2.0 directly to project ChinookCoreAPI to resolve this issue.
ChinookCoreAPI -> Microsoft.EntityFrameworkCore.SqlServer 2.2.0 ->
Microsoft.EntityFrameworkCore.Relational 2.2.0 ->
Microsoft.EntityFrameworkCore (>= 2.2.0)
ChinookCoreAPI -> Microsoft.AspNetCore.App 2.1.1 ->
Microsoft.EntityFrameworkCore (>= 2.1.1 && < 2.2.0).
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.SqlServer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManag
ement.PowerShellCmdlets.InstallPackageCommand
Install-Package : Package restore failed. Rolling back package changes for
'ChinookCoreAPI'.
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.SqlServer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManag
ement.PowerShellCmdlets.InstallPackageCommand
Can Someone help me solve this as I am new to this.
回答1:
EF Core and ASP.NET Core (were) used to ship together. In ASP.NET Core 2.x (Microsoft.AspNetCore.App
/Microsoft.AspNetCore.App
meta packages), EF Core is part of ASP.NET Core meta packages (see Microsoft.AspNetCore.App metapackage for ASP.NET Core 2.1).
With ASP.NET Core 3.0, EntityFrameworkCore, JSON.NET and Microsoft.CodeAnalysis won't be party of Microsoft.AspNetCore.App/All
packages anymore. See the GitHub announcement.
You are getting this issue, because Install-Package Microsoft.EntityFrameworkCore.SqlServer
is installing the latest version of EF Core (2.2) while your ASP.NET Core application is still at 2.1.
Or upgrade your application to ASP.NET Core 2.2.
But the issue here seems that ChinookCoreAPI
requires the older version of ASP.NET Core (and EF Core), namely 2.1. From your question its not clear if you did the Install-Package Microsoft.EntityFrameworkCore.SqlServer
on your application project or on ChinookCoreAPI
. If its on Install-Package Microsoft.EntityFrameworkCore.SqlServer
installing the newest EF Core on the App project should fix it. Otherwise lower the verison of ChinookCoreAPI
to 2.1.1
回答2:
Your Current Version of ASPNET Core (Microsoft.AspNetCore.App 2.1.1) does not support latest Version of EFCore (Microsoft.EntityFrameworkCore 2.2.0).
In Startup.cs, Decrease the EF Version, as "Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.1" And Restore again.
This worked for me.
来源:https://stackoverflow.com/questions/53792122/detected-package-version-outside-of-dependency-constraint-microsoft-aspnetcore