【问题标题】:dotnet ef command no longer works after upgrading to Visual Studio 16.3.0升级到 Visual Studio 16.3.0 后,dotnet ef 命令不再有效
【发布时间】:2020-01-24 09:18:00
【问题描述】:

这首先发生在家里,所以我想这可能是我家里的台式电脑的问题。但是现在我回来工作了,我尝试升级并得到了同样的东西。

升级前的屏幕截图

升级 Visual Studio 后的屏幕截图

我得到的错误是:

无法执行,因为找不到指定的命令或文件。

可能的原因包括:

  • 您拼错了内置的 dotnet 命令。
  • 您打算执行 .NET Core 程序,但 dotnet-ef 不存在。
  • 您打算运行全局工具,但在 PATH 上找不到具有此名称的 dotnet 前缀可执行文件。

关于为什么会发生这种情况的任何想法?以及如何取回dotnet ef 命令。我的意思是之前一定是在$PATH,否则它以前不会工作。

【问题讨论】:

    标签: entity-framework entity-framework-core dotnet-cli entity-framework-core-3.0


    【解决方案1】:

    这是breaking change in Entity Framework Core 3.0

    EF Core 命令行工具 dotnet ef 不再是 .NET Core SDK 的一部分。

    ...

    从 3.0 开始,.NET SDK 不包含 dotnet ef 工具,因此在使用它之前,您必须将其显式安装为本地或全局工具。

    您需要安装Entity Framework Core Tools。要全局安装,请在命令行上运行:

    dotnet tool install --global dotnet-ef
    

    【讨论】:

    • 如果我有一个较旧的项目(在 Core 2.0 上)需要增强。我可以使用 3.0 SDK 的工具将ef migration 添加到 2.0 项目吗?
    • @Grandizer 为什么要使用 3.0 SDK?只需使用与您的代码匹配的 2.x,无论如何您都会安装它。
    • @DavidG - 完美,但我得到了这个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. 并试图弄清楚。
    • @DavidG 我发现使用 2.x,但根据上述错误消息如何强制它访问该版本并不明显。这是我添加迁移 dotnet ef migrations add EmployeeUtilization -s ..\Almanac 的命令,该命令对整个项目都有效,直到我开始处理 .NET Core 3 项目并安装了该 SDK。
    • 所以阅读here 我从我的回购基础上做了dotnet tool install --local --version 2.0 dotnet-ef。那行得通!之前做过,但不确定我是否需要:dotnet new tool-manifest
    猜你喜欢
    • 2019-11-13
    • 2021-05-25
    • 2014-10-10
    • 2021-12-21
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    相关资源
    最近更新 更多