You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

手动安装二进制包版.NET后dotnet ef命令执行失败求助

问题:dotnet ef命令提示找不到.NET环境(已正常安装.NET SDK)

当前环境信息

执行dotnet --info输出如下:

.NET SDK (reflecting any global.json):
 Version:   6.0.401
 Commit:    0906eae6f8

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.6
 OS Platform: Darwin
 RID:         osx.12-arm64
 Base Path:   /opt/homebrew/opt/dotnet@6/sdk/6.0.401/

global.json file:
  Not found

Host:
  Version:      6.0.9
  Architecture: arm64
  Commit:       163a63591c

.NET SDKs installed:
  6.0.401 [/opt/homebrew/opt/dotnet@6/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.9 [/opt/homebrew/opt/dotnet@6/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.9 [/opt/homebrew/opt/dotnet@6/shared/Microsoft.NETCore.App]

Download .NET:
  https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs:
  https://aka.ms/dotnet/runtimes-sdk-info

执行dotnet ef时的错误信息

You must install .NET to run this application.

App: /Users/bkalbuaji/.dotnet/tools/dotnet-ef
Architecture: arm64
App host version: 6.0.9
.NET location: Not found

Learn about runtime installation:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=arm64&rid=osx.12-arm64&apphost_version=6.0.9

解决方案

1. 确认DOTNET_ROOT环境变量配置

手动安装的.NET需要明确指定DOTNET_ROOT指向安装目录,执行以下命令临时生效:

export DOTNET_ROOT=/opt/homebrew/opt/dotnet@6

要永久生效,将上述命令添加到你的shell配置文件中(如~/.zshrc或~/.bash_profile),然后执行source ~/.zshrc(对应你的配置文件)刷新环境变量。

2. 检查PATH环境变量

确保PATH包含.NET安装目录和工具目录,执行以下命令临时生效:

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

同样,将该命令添加到shell配置文件中永久生效。

3. 重新安装dotnet ef工具(指定架构)

卸载现有工具后,针对ARM64架构重新安装匹配版本的dotnet ef:

dotnet tool uninstall --global dotnet-ef
dotnet tool install --global dotnet-ef --arch arm64 --version 6.0.9

版本号需与已安装的.NET runtime版本(6.0.9)保持一致。

4. 验证dotnet命令路径

执行which dotnet,确认输出为/opt/homebrew/opt/dotnet@6/dotnet。如果不是,创建符号链接指向正确的dotnet可执行文件:

sudo ln -s /opt/homebrew/opt/dotnet@6/dotnet /usr/local/bin/dotnet

完成以上步骤后,重新打开终端执行dotnet ef即可验证是否解决问题。

内容的提问来源于stack exchange,提问作者Bharata

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 00:45:40