Visual Studio 2022 for Mac无法识别.NET Core SDK位置求助
解决Visual Studio 2022 for Mac无法识别.NET SDK的问题
方法1:手动在VS中指定SDK路径
- 打开Visual Studio 2022 for Mac,点击顶部菜单栏的Visual Studio → Settings
- 在设置窗口选择Projects → .NET Runtimes
- 点击右下角的**+**,添加
dotnet --list-sdks显示的SDK目录:/opt/homebrew/Cellar/dotnet/7.0.100/libexec/sdk - 若已安装.NET 6,同理添加对应版本的SDK目录(格式类似
/opt/homebrew/Cellar/dotnet/6.x.x/libexec/sdk) - 点击Apply保存,重启Visual Studio
方法2:配置环境变量引导VS识别
- 终端打开shell配置文件:
- zsh用户:
open ~/.zshrc - bash用户:
open ~/.bash_profile
- zsh用户:
- 添加以下环境变量:
(也可直接指向Homebrew的dotnet统一路径export DOTNET_ROOT=/opt/homebrew/Cellar/dotnet/7.0.100/libexec export PATH=$PATH:$DOTNET_ROOT/bin/opt/homebrew/opt/dotnet/libexec,该路径兼容已安装的所有.NET版本) - 保存文件后执行
source ~/.zshrc(或对应shell的source命令)生效,重启VS
方法3:修复Homebrew的dotnet关联
- 终端执行命令创建正确的符号链接:
brew link dotnet - 执行
which dotnet确认输出为/opt/homebrew/bin/dotnet - 再次运行
dotnet --list-sdks确认SDK列表正常后,重启VS
方法4:重置VS的SDK缓存
- 关闭Visual Studio
- 终端执行命令删除缓存目录:
rm -rf ~/Library/Application\ Support/VisualStudio/17.0/LocalInstall/Addins/Microsoft.VisualStudio.Web.Mac.NetCore - 重新打开VS,它会自动重新扫描系统中的.NET SDK
内容的提问来源于stack exchange,提问作者Badhan Sen
相关产品推荐
相关产品推荐

