JetBrains Rider 2025.3 Help

Entity Framework Core:故障排除

项目未出现在“启动项目”字段中

检查所需项目是否满足以下要求:

  • 已安装 Microsoft.EntityFrameworkCore.DesignMicrosoft.EntityFrameworkCore.Tools NuGet 包。

  • 项目的目标框架至少为 netcoreapp3.1.

全局安装的 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-xyz 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/tools 文件夹包含在 PATH 环境变量中。 有关更多信息,请参阅此 故障排除指南

在 Windows 上,您还可以运行 .NET SDK 安装程序并选择“修复”选项。

在 Linux 或 macOS 上无法使用 'update database'、'add migration' 或其他命令

症状

使用 EF Core 的可视化接口时,特别是在 Rider 作为 Snap 软件包安装时,出现 Command not foundNo such file or directory 错误。

根本问题

从 Linux 桌面启动时,Rider 可能不会加载终端配置中设置的环境变量,这会导致其无法找到 dotnet 可执行文件和 dotnet-ef 全局工具,从而即使命令在独立终端中正常工作,也会导致可视化接口失败。

解决方案

  1. 请确保您的系统满足 先决条件

  2. 将以下行添加到用于图形会话的用户配置文件中。 在大多数 Linux 发行版和 macOS 上,这是 ~/.profile ,但其他 shell 可能使用不同的配置文件,例如 Bash 使用 ~/.bashrc ,Zsh 使用 ~/.zshrc。 如果文件存在,请将该行添加到文件末尾;否则,请创建该文件。

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

    将此行添加到您的配置文件中,将允许终端及其继承环境的应用程序访问 .NET SDK 及其工具。

  3. 注销当前会话并重新登录,或者重启计算机以使更改生效。

  4. 通过打开 IDE Scripting Console,在 Rider 中验证 PATH。 按下 Ctrl+Shift+A 并搜索“IDE Scripting Console”,然后运行:

    System.getenv("PATH");

    您应该看到 /home/username/.dotnet/home/username/.dotnet/tools 出现在路径中。

最后修改日期: 2025年 12月 5日