无法创建迁移,因为无法识别 EntityFramework.Design 包

Can't create migration because EntityFramework.Design package isn't recognized

我安装了EntityFrameworkCore.Design运行以下。

Install-Package Microsoft.EntityFrameworkCore.Design -Version 3.0.0-preview6.19304.10

好像已经安装好了,在VS中可以看到如下

但是,当我尝试使用

创建迁移时
dotnet ef migrations add Init

我等了好久,然后出现以下错误。

Your startup project 'Web' 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.

当我检查 Web.proj 文件时,我看到了以下部分。

<ItemGroup>
  <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.0.0-preview6.19307.2" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0-preview6.19304.10">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
  </PackageReference>
  <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0-preview6.19304.10" />
  <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc2" />
  <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0-rc2" />
</ItemGroup>

如何确保电脑能看到包裹?

您需要参考其他包才能使迁移工作, 添加:

Microsoft.EntityFrameworkCore.Tools

将其添加到具有数据上下文的项目中。