在.NET Core 3中找不到dotnet ef [英] dotnet ef not found in .NET Core 3

查看:254
本文介绍了在.NET Core 3中找不到dotnet ef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注文档以创建初始迁移。当我执行 dotnet 时,我得到了帮助部分,这意味着PATH可以正常工作。

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  

我收到以下错误:


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.




  • 自从复制命令以来,我排除了第一项。

  • 我排除了第二项,因为安装了软件包 Microsoft.EntityFrameworkCore.SqlServer

  • 我排除了第三项,因为我得到了

  • 我正在谷歌搜索问题,但是由于该版本是新版本,因此没有太多工作要做,并且/或者它淹没了较早版本中的类似问题。

    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.

    我试图强行安装 Microsoft .EntityFrameworkCore ,以防需要显式添加。我遇到错误消息,告诉我要选择的最新版本是2.2.6,降级是不行的。我不确定如何安装与我的系统上已有的SQL软件包兼容的版本(甚至无法确定这是否是解决此问题的正确方法)。

    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).

    检测到的包降级:Microsoft.EntityFrameworkCore从3.0.0-preview6.19304.10降为2.2.6。直接从项目中引用该软件包以选择其他版本。

    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)

    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:


    dotnet ef工具不再是.NET Core SDK的一部分



    此更改使我们可以将 dotnet ef 作为常规.NET CLI工具发布,可以将其安装为全局或全局本地工具。例如,为了能够管理迁移或搭建 DbContext ,请安装 dotnet ef 作为全局工具,键入以下内容命令:

    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 --version 3.0.0
    

    更改的原因在文档


    为什么



    此更改使我们可以在NuGet上作为常规.NET CLI工具分发和更新 dotnet ef ,这与EF Core 3.0也始终以NuGet软件包的形式分发。

    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.

    此外,您可能需要在项目中添加以下NuGet软件包:

    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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆