安装的 Dotnet 工具出现错误“无法执行,因为找不到指定的命令或文件。” 在 Ubuntu WSL2 上

Bir*_*Dad 2 c# entity-framework command-line-interface .net-core wsl-2

我正在 wsl2 中的 .net core 5 中开发 api,并按照所有文档安装实体框架核心工具。

当我跑步时

dotnet tool list -g
Run Code Online (Sandbox Code Playgroud)

它打印

Package Id      Version      Commands
--------------------------------------
dotnet-ef       5.0.7        dotnet-ef
Run Code Online (Sandbox Code Playgroud)

但当我跑步时

dotnet ef
Run Code Online (Sandbox Code Playgroud)

或其任何子命令,我明白了

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 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.
Run Code Online (Sandbox Code Playgroud)

现在,我看着我的道路,看起来就像我跑步时一样

dotnet tool install --global dotnet-ef
Run Code Online (Sandbox Code Playgroud)

它将它安装在我的 C 驱动器下而不是 wsl2 内,我认为这可能是问题所在,但我不明白为什么在 ubuntu 中运行它将它安装到我的 Windows 目录中,但这是我路径中的行

/mnt/c/Users/ethan/.dotnet/tools
Run Code Online (Sandbox Code Playgroud)

所以我想我的问题是,它在我的 Windows 目录下卸载的问题是,如果是这样,我该如何强制它安装在 ububtu 上或更改我的路径,如果不是的话,会发生什么。

Bir*_*Dad 8

我找到了这篇文章: 找不到命令“dotnet ef”

和跑步

export PATH="$PATH:$HOME/.dotnet/tools/"
Run Code Online (Sandbox Code Playgroud)

使 dotnet ef 工作,直到我开始一个新的终端会话,所以我想仔细检查正确的方法以使其永久修复,根据这篇文章,我发现https://astrobiomike.github.io/unix/modifying_your_path是最好的方法处理它只是将其添加到您的 bash_profile 或 zshrc 中,这就是我所做的