.NET Core 3.0中使用dotnet ef migrations add InitialCreate命令,报错如下,Could not execute because the specified command or file was not found. Possible reasons for this include: * You misspelled a built-in dotnet command. * You intended to execute a .NET Core program, but dotnet-ef does not exist. * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH. 执行dotnet命令,可以正常执行,说明PATH正常,本文主要介绍一下解决方法。

显示安装dotnet ef工具

请参阅有关ASP.NET Core 3相关文档,dotnet ef工具不再是.NET Core SDK的一部分,此更改使我们可以dotnet ef作为常规.NET CLI工具发布,可以将其安装为全局或本地工具。例如,为了能够管理迁移或搭建DbContext,请dotnet ef输入以下命令作为全局工具安装:

dotnet tool install --global dotnet-ef



此更改允许我们在 NuGet 上将 dotnet ef 作为常规 .NET CLI 工具分发和更新,这与 EF Core 3.0 也始终作为 NuGet 包分发的事实一致。