JetBrains Rider 2026.1 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 的图形界面时出现 Command not foundNo such file or directory 错误,尤其是在将 Rider 作为 Snap 软件包安装时。

根本问题

从 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. 在 Rider 中打开 IDE Scripting Console,验证 PATH。 按下 Ctrl+Shift+A 并搜索 'IDE Scripting Console',然后运行:

    System.getenv("PATH");

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

2026年 3月 25日