c# - 安装的 Dotnet 工具在 Ubuntu WSL2 上给出错误 "Could not execute because the specified command or file was not found."

标签 c# entity-framework .net-core command-line-interface wsl-2

我正在 wsl2 的 .net core 5 中开发一个 api,我按照所有文档安装了 Entity Framework 核心工具。

当我运行时

dotnet tool list -g

它打印

Package Id      Version      Commands
--------------------------------------
dotnet-ef       5.0.7        dotnet-ef

但是当我运行的时候

dotnet ef

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

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.

现在,我看着我的路径,看起来就像我运行时的样子

dotnet tool install --global dotnet-ef

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

/mnt/c/Users/ethan/.dotnet/tools

所以我想我的问题是,问题是它在我的 Windows 目录下没有停止吗?如果是,我如何强制它安装在 ububtu 上或更改我的路径,如果没有,发生了什么。

最佳答案

我找到这篇文章: Cannot find command 'dotnet ef'

正在运行

export PATH="$PATH:$HOME/.dotnet/tools/"

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

关于c# - 安装的 Dotnet 工具在 Ubuntu WSL2 上给出错误 "Could not execute because the specified command or file was not found.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68108640/

相关文章:

c# - 使用多种分隔符类型将文本文件解析为字段

C# Core 2.0 - 根据另一个模型中的数据从一个模型获取数据?

c# - 在 NET Core 中调用从 C++ 项目构建的 .dll 时出现 BadImageFormatException

mysql - 如何在一处维护EF连接字符串?

c# - 使用预加载和显式加载查询相关实体在 EF for ASP.NET MVC CORE 中不起作用

c# - Entity Framework Core 根据类的类型显式加载相关数据

c# - Ruby Sequel 等同于 LINQ to SQL 选择匿名对象

c# - 当调用者期望特定的构造函数签名时使用构造函数注入(inject)

c# - 如何在没有 XAML 的情况下将换行符插入 TextBlock?

c# - sub linq 查询使这需要很长时间,我怎样才能使它更快?