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

7

我一直在不同的操作系统中尝试测试 dotnet core 3,如WindowsLinux(Ubuntu)。它们都与 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时遇到了相同的错误?

3个回答

12

终于找到了解决方法!

我尝试按 @kapsiR 的建议导出 PATH 变量 export PATH="$PATH:$HOME/.dotnet/tools",但它只对单个终端会话有效。因此,如果我关闭终端并重新打开,$PATH 配置就会消失。

对我有效的解决方案:

  1. cd /home/yourUserName
  2. 编辑文件 .zshrc 并添加以下行 export PATH="$PATH:$HOME/.dotnet/tools/"注意:在这种情况下,我正在使用 zsh shell。如果您使用不同的 shell,请相应更改。
  3. 重新启动终端

7

不幸的是,在安装dotnet-sdk后,PATH并没有直接被导出。

你基本上有两个选择:

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

OR

  1. 启动一个新的WSL会话

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


谢谢@kapsiR。我已经尝试了第一个选项。然而,它仅适用于单个终端会话。如果我关闭终端并重新打开,它就消失了! - Willian

0
在Ubuntu中使用`dotnet-ef`,我们需要运行以下命令将`dotnet-sdk`添加到Ubuntu中。
sudo apt upgrade dotnet-sdk-7.0

或者

sudo apt upgrade dotnet-sdk-6.0

下一步,使用以下命令添加 dotnet-ef
dotnet tool install --global dotnet-ef --version 7.0.13

更多信息请参考以下参考资料:
Nuget
Microsoft

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接