使用dotnet-ef添加InitialCreate迁移失败的问题求助
dotnet-ef添加InitialCreate迁移失败的问题求助
大家好,我正在给我的应用集成Entity Framework,之前应用编译和启动都完全正常,但尝试添加迁移的时候遇到了一堆奇怪的错误,想请大家帮忙看看到底哪里出问题了。
首先我在Debug/net8.0目录下执行了这条命令:
dotnet dotnet-ef migrations add InitialCreate
结果直接报错:
Cannot execute because the specified command or file is not found.
Possible reasons for this are as follows:
- The dotnet built-in command was written incorrectly.
- A .NET program was intended to execute, but dotnet-dotnet-ef does not exist.
- A global tool was intended to be executed, but an executable file with the dotnet prefix of that name cannot be found in the PATH path.
我以为是工具路径的问题,又尝试直接调用工具的绝对路径:
~/.dotnet/tools/dotnet-ef migrations add InitialCreate
结果还是报错,这次提示找不到.NET:
You must install .NET to run this application.
App: /home/kamil/.dotnet/tools/dotnet-ef
Architecture: x64
App host version: 8.0.2
.NET location: Not found
然后我特意查了当前的.NET环境状态,执行dotnet --info得到的结果是:
.NET SDK: Version: 8.0.200 Commit: 438cab6a9d Workload version: 8.0.200-manifests.cdf2cc8e Launch environment: OS Name: ubuntu OS Version: 22.04 OS Platform: Linux RID: linux-x64 Base Path: /snap/dotnet-sdk/236/sdk/8.0.200/ Installed .NET platform workloads: No installed workloads to display. Host: Version: 8.0.2 Architecture: x64 Commit: 1381d5ebd2 .NET SDKs installed: 8.0.200 [/snap/dotnet-sdk/236/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 8.0.2 [/snap/dotnet-sdk/236/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 8.0.2 [/snap/dotnet-sdk/236/shared/Microsoft.NETCore.App] Other architectures found: None Environment variables: Not set global.json file: Not found
我还检查了DOTNET_ROOT环境变量:
echo $DOTNET_ROOT
输出是:
/snap/dotnet-sdk/236/sdk
而且我确实已经全局安装了dotnet-ef工具:
dotnet tool install --global dotnet-ef
实在搞不懂到底哪里出问题了,有没有大佬能帮忙分析一下?
备注:内容来源于stack exchange,提问作者Kamil Nowiński
相关产品推荐
相关产品推荐

