.NET 8.0.7环境下执行dotnet ef migrations命令失败求助
已安装.NET 8.0.7和dotnet-ef,但执行迁移命令提示找不到.NET环境
问题描述
在.NET 8.0.7环境下执行Entity Framework迁移命令:
dotnet ef migrations add UpdateJob
触发如下错误:
You must install .NET to run this application. App: /home/radu/.dotnet/tools/dotnet-ef Architecture: x64 App host version: 8.0.7 .NET location: Not found Learn more: https://aka.ms/dotnet/app-launch-failed Download the .NET runtime: https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=linux-x64&os=ubuntu.22.04&apphost_version=8.0.7
已确认dotnet-ef工具已安装:
Tool 'dotnet-ef' was reinstalled with the stable version (version '8.0.7').
本地dotnet info输出如下:
.NET SDK: Version: 8.0.303 Commit: 29ab8e3268 Workload version: 8.0.300-manifests.c915c39d MSBuild version: 17.10.4+10fbfbf2e Runtime Environment: OS Name: ubuntu OS Version: 22.04 OS Platform: Linux RID: linux-x64 Base Path: /usr/share/dotnet/sdk/8.0.303/ .NET workloads installed: There are no installed workloads to display. Host: Version: 8.0.7 Architecture: x64 Commit: 2aade6beb0 .NET SDKs installed: 8.0.303 [/usr/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 8.0.7 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 8.0.7 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Other architectures found: None Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download
解决方法
配置环境变量:确保
DOTNET_ROOT指向正确的.NET安装路径,临时生效可执行:export DOTNET_ROOT=/usr/share/dotnet export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools如需永久生效,将上述命令添加到
~/.bashrc(或~/.zshrc,根据使用的shell调整),执行source ~/.bashrc刷新配置。重新绑定dotnet-ef工具:卸载后重新安装并指定.NET 8.0框架,确保工具关联到本地已安装的.NET环境:
dotnet tool uninstall --global dotnet-ef dotnet tool install --global dotnet-ef --framework net8.0验证修复结果:执行
dotnet ef --version,若能正常输出dotnet-ef的版本信息,说明问题已解决,可重新执行迁移命令。
内容的提问来源于stack exchange,提问作者Radu M.
相关产品推荐
相关产品推荐

