由于软件包不兼容,添加迁移失败

add-migration fails due to incompatability of packages

我连接到我在 Micrososft SQL Server Management Studio 中创建的 SQL 服务器数据库。我使用我当前的 ip 连接。

打开连接和数据库的那天,我还使用迁移和 Entity Framework 创建了一个 table,table 创建成功。

晚上关机早上回来上班,我尝试在PM Console中执行添加迁移我得到错误:

Your startup project 'TowerOfPower' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.

很奇怪,但是当我尝试安装软件包时

Install-Package Microsoft.EntityFrameworkCore.Design -Version 2.1.0

我收到错误:

Install-Package : Could not install package 'Microsoft.EntityFrameworkCore.Design 2.1.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.Design -Version 2.1.0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

所以我尝试按照网上的建议安装其他软件包来解决这个问题,但仍然出现我为所有这些软件包提到的最后一个错误。

我认为你的框架类型有很大的矛盾。首先,如果你开发 .NetCore 项目,你必须使用 EfCore 进行 ORM 进度。在 .NetFramework 项目中,您必须使用 Entity Framework.

如果我们查看最新的错误信息,
您正在尝试加载不正确的 nuget 项目。根据错误消息,您尝试将 EntityFrameworkCore packege 安装到 ".NETFramework,Version=v4.0'" 为此你必须使用 Install-Package EntityFramework -Version 6.2.0

的框架

最后,如果您在单个解决方案中使用多个项目,则必须确定项目框架类型(例如:.Net 或 .NetCore)

当您使用包管理器控制台时,您必须在默认项目组合框

中选择正确的项目