将 dotnet-ef 与 docker 和 asp.net core 3.1 一起使用

Sig*_*gGP 6 entity-framework docker entity-framework-migrations asp.net-core-3.1

我正在尝试在 docker 上运行用 asp.net core 3.1 编写的应用程序。我需要使用迁移创建数据库。执行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.
Run Code Online (Sandbox Code Playgroud)

据我了解,我需要安装 dotnet-ef 工具。在容器中执行此操作的正确方法是什么?

Voč*_*čko 9

就像 @harili 所说,您必须安装它并将其添加到 PATH 环境变量中。

来自 Dockerfile:

RUN dotnet tool install --global dotnet-ef
ENV PATH="$PATH:/root/.dotnet/tools"
Run Code Online (Sandbox Code Playgroud)


har*_*ili 0

可能是您没有安装 EF 工具:

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

并按照 @Vo\xc4\x8dko 建议添加环境路径:

\n
ENV PATH="$PATH:/root/.dotnet/tools"\n
Run Code Online (Sandbox Code Playgroud)\n