【问题标题】:dotnet-ef does not exist - Windows 10 WSL (Ubuntu)dotnet-ef 不存在 - Windows 10 WSL (Ubuntu)
【发布时间】:2020-09-22 16:14:57
【问题描述】:

我一直在 WindowsLinux(Ubuntu) 等不同操作系统中测试 dotnet core 3。他们都可以在 EF Core 中正常工作!

但是,我决定给Windows WSL - Windows Subsystem for Linux 一个机会,看看它是如何工作的。这就是我在这里的原因!

WSL 和 Ubuntu 18.04 的问题是:

我全局安装了 EF Core 并重新启动了终端。 * 到目前为止,EF 版本为 3.1.4

> dotnet tool install --global dotnet-ef

当我尝试运行任何dotnet ef 命令时出现以下错误:

> dotnet ef database update

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.

有人在使用 Windows WSLUbuntu 18.04 时遇到过同样的错误吗?

【问题讨论】:

    标签: entity-framework .net-core windows-subsystem-for-linux ef-core-3.0


    【解决方案1】:

    遗憾的是,PATH 在安装 dotnet-sdk 后不会直接导出。
    你基本上有两个选择:

    1. 为当前会话手动添加工具路径:
      export PATH="$PATH:$HOME/.dotnet/tools"

    1. 开始新的 WSL 会话

    dotnet-sdk 附带一个将其添加到PATH 的脚本,它位于/etc/profile.d/dotnet-cli-tools-bin-path.sh 下。

    【讨论】:

    • 谢谢@kapsiR。我已经尝试过第一个选项。但是,它仅对单个终端会话有效。如果我关闭终端并再次打开,它就消失了!
    【解决方案2】:

    我终于找到了解决办法!

    我已尝试将 PATH 变量 export PATH="$PATH:$HOME/.dotnet/tools" 导出为 @kapsiR 提到的。但是,它仅对单个终端会话有效。因此,如果我关闭终端并再次打开,$PATH 配置就会消失。

    适合我的解决方案:

    1. cd /home/yourUserName
    2. 编辑文件.zshrc并添加这一行export PATH="$PATH:$HOME/.dotnet/tools/"注意:在这种情况下,我使用的是 zsh shell。如果你使用的是不同的,你应该改变它。
    3. 重启终端

    【讨论】:

      猜你喜欢
      • 2020-02-12
      • 2023-03-03
      • 2020-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-19
      • 2019-11-07
      • 1970-01-01
      相关资源
      最近更新 更多