简体   繁体   English

为什么 Entity Framework Core 迁移需要 .NET Core 2.x?

[英]Why do Entity Framework Core migrations require .NET Core 2.x?

In my .NET5.0 project the PostgreSQL Nuget package is installed ( Npgsql.EntityFrameworkCore.PostgrSQL (5.0.2) ) and its dependency of EF Core ( Microsoft.EntityFrameworkCore (5.0.2) ). In my .NET5.0 project the PostgreSQL Nuget package is installed ( Npgsql.EntityFrameworkCore.PostgrSQL (5.0.2) ) and its dependency of EF Core ( Microsoft.EntityFrameworkCore (5.0.2) ).

I'm trying to create a migration using this command:我正在尝试使用以下命令创建迁移:

dotnet ef migrations add InitialCreate

However, the migration fails because I'm requested to install .NET Core 2.0.0 - following the recommended download link I'm told that it's no longer available and that I would likely want to use 5.0.但是,迁移失败,因为我被要求安装 .NET Core 2.0.0 - 按照推荐的下载链接,我被告知它不再可用并且我可能想要使用 5.0。 How the heck can I run the migration?我怎么能运行迁移?

This is what the output looks:这是 output 的外观:

Build started...
Build succeeded.
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.0.0' was not found.
  - The following frameworks were found:
      3.1.11 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
      3.1.12 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
      3.1.13 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
      5.0.3 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
      5.0.4 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=osx.11.0-x64

Make sure you have <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5" /> in your csproj.确保您的 csproj 中有<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5" /> Also try updating the dotnet-ef tool: dotnet tool update --global dotnet-ef .还可以尝试更新 dotnet-ef 工具: dotnet tool update --global dotnet-ef

I performed these actions and the issue went away.我执行了这些操作,问题就消失了。

This can occur if you run the command in a class library.如果您在 class 库中运行该命令,可能会发生这种情况。 You can point to the startup-project when running the command:运行命令时可以指向startup-project

dotnet ef migrations add InitialCreate --startup-project <PathToProject>

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

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