.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
项目中添加以下NuGet软件包:
更改原因:
此更改允许我们在 NuGet 上将 dotnet ef 作为常规 .NET CLI 工具分发和更新,这与 EF Core 3.0 也始终作为 NuGet 包分发的事实一致。
相关文档:https://docs.microsoft.com/zh-cn/ef/core/what-is-new/ef-core-3.0/breaking-changes#the-ef-core-command-line-tool-dotnet-ef-is-no-longer-part-of-the-net-core-sdk