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

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
  • 添加以下环境变量:
    export DOTNET_ROOT=/opt/homebrew/Cellar/dotnet/7.0.100/libexec
    export PATH=$PATH:$DOTNET_ROOT/bin
    
    (也可直接指向Homebrew的dotnet统一路径/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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 02:52:13