dotnet-ef 不存在 - Windows 10 WSL (Ubuntu)

dotnet-ef does not exist - Windows 10 WSL (Ubuntu)

我一直在不同的 OS 中测试 dotnet core 3,比如 WindowsLinux(Ubuntu)。所有这些都与 EF Core 一起正常工作!

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

WSL和Ubuntu18.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 时遇到同样的错误?

遗憾的是,安装 dotnet-sdkPATH 没有直接导出。
您基本上有两个选择:

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

  1. 开始 WSL 的新会话

随着 dotnet-sdk 有一个脚本将其添加到 PATH,它位于 /etc/profile.d/dotnet-cli-tools-bin-path.sh.

终于找到解决办法了!

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

适合我的解决方案:

  1. cd /home/yourUserName
  2. 编辑文件 .zshrc 并添加此行 export PATH="$PATH:$HOME/.dotnet/tools/"注意:在本例中我使用的是 zsh shell。如果您使用不同的,您应该更改它。
  3. 重启终端