在 .NET Core 3 中找不到命令 dotnet ef [英] Command dotnet ef not found in .NET Core 3
问题描述
我正在关注 文档 以创建初始迁移.当我执行 dotnet
时,我得到了帮助部分,这意味着 PATH 工作正常.
然后我尝试从控制台窗口中的文档执行以下命令:
<块引用>dotnet ef 迁移添加 InitialCreate
我收到以下错误:
<块引用>无法执行,因为找不到指定的命令或文件.
可能的原因包括:
您拼错了一个内置的 dotnet 命令.
您打算执行 .NET Core 程序,但 dotnet-ef 不存在.
您打算运行一个全局工具,但在 PATH 中找不到具有此名称的带有 dotnet 前缀的可执行文件.
因为我复制了命令,所以我排除了第一项.
我排除了第二项,因为安装了 Microsoft.EntityFrameworkCore.SqlServer 包.
我排除了第三项,因为我在调用 dotnet 时得到了帮助部分.
我正在谷歌上搜索这个问题,但由于版本是新的,所以没有什么可做的和/或它淹没在早期版本的类似问题中.
我试图强行安装 Microsoft.EntityFrameworkCore 以防万一需要明确添加.我遇到了错误消息,告诉我要选择的最新版本是 2.2.6,不能降级.我不确定如何安装与我系统上已有的 SQL 包兼容的版本(甚至不确定这是否是解决此问题的正确方法).
<块引用>检测到包降级:Microsoft.EntityFrameworkCore 从 3.0.0-preview6.19304.10 到 2.2.6.直接从项目中引用包以选择不同的版本.
网页 ->
Microsoft.EntityFrameworkCore.SqlServer 3.0.0-preview6.19304.10 ->
Microsoft.EntityFrameworkCore.Relational 3.0.0-preview6.19304.10 ->
Microsoft.EntityFrameworkCore (>= 3.0.0-preview6.19304.10)
网络 ->Microsoft.EntityFrameworkCore (>= 2.2.6)
请参阅 公告 ASP.NET Core 3 Preview 4,其中说明此工具不再是内置工具,需要显式安装:
<块引用>dotnet ef 工具不再是 .NET Core SDK 的一部分
此更改使我们能够将 dotnet ef
作为常规 .NET CLI 工具发布,该工具可安装为全局或本地工具.例如,为了能够管理迁移或构建 DbContext
,请安装 dotnet ef
作为全局工具,键入以下命令:
dotnet 工具安装 --global dotnet-ef
要安装该工具的特定版本(在 nuget 查看所有可用版本.org),使用以下命令:
dotnet 工具安装 --global dotnet-ef --version 3.1.4
更改的原因在 文档:
<块引用>为什么
此更改允许我们在 NuGet 上将 dotnet ef
作为常规 .NET CLI 工具分发和更新,这与 EF Core 3.0 也始终作为 NuGet 包分发的事实一致.>
此外,您可能需要将以下 NuGet 包添加到您的项目中:
- Microsoft.EntityFrameworkCore.SqlServer
- Microsoft.EntityFrameworkCore.Design
- Microsoft.EntityFrameworkCore.Tools
I'm following the docs in order to create an initial migration. When I execute dotnet
, I get the help section, meaning that the PATH works properly.
Then I try to execute the command below from the docs in console window:
dotnet ef migrations add InitialCreate
I get the following error:
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.
I excluded the first item since I copied the command.
I excluded the second item because the package Microsoft.EntityFrameworkCore.SqlServer is installed.
I excluded the third item because I get the help section when invoking dotnet.
I'm googling the issue but since the version is new, there's not much to go on and/or it's drowning in similar issues from earlier versions.
I tried to forcibly install Microsoft.EntityFrameworkCore just in case it needs to be explicitly added. I ran into the error message telling me that the latest version to pick from is 2.2.6 and a downgrade is a no-go. I'm not sure how to install the version compatible with the SQL-package I have on my system already (and even less certain if that's right approach to kill this issue).
Detected package downgrade: Microsoft.EntityFrameworkCore from 3.0.0-preview6.19304.10 to 2.2.6. Reference the package directly from the project to select a different version.
Web ->
Microsoft.EntityFrameworkCore.SqlServer 3.0.0-preview6.19304.10 ->
Microsoft.EntityFrameworkCore.Relational 3.0.0-preview6.19304.10 ->
Microsoft.EntityFrameworkCore (>= 3.0.0-preview6.19304.10)
Web -> Microsoft.EntityFrameworkCore (>= 2.2.6)
See the announcement for ASP.NET Core 3 Preview 4, which explains that this tool is no longer built-in and requires an explicit install:
The dotnet ef tool is no longer part of the .NET Core SDK
This change allows us to ship dotnet ef
as a regular .NET CLI tool that can be installed as either a global or local tool. For example, to be able to manage migrations or scaffold a DbContext
, install dotnet ef
as a global tool typing the following command:
dotnet tool install --global dotnet-ef
To install a specific version of the tool (see all available versions at nuget.org), use the following command:
dotnet tool install --global dotnet-ef --version 3.1.4
The reason for the change is explained in the docs:
Why
This change allows us to distribute and update dotnet ef
as a regular .NET CLI tool on NuGet, consistent with the fact that the EF Core 3.0 is also always distributed as a NuGet package.
In addition, you might need to add the following NuGet packages to your project:
- Microsoft.EntityFrameworkCore.SqlServer
- Microsoft.EntityFrameworkCore.Design
- Microsoft.EntityFrameworkCore.Tools
这篇关于在 .NET Core 3 中找不到命令 dotnet ef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!