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

Visual Studio for Mac 2022预览版添加NuGet源显示不可达如何修复

问题描述

安装Visual Studio Community 2022 for Mac Preview 17.3(build 198)版本后,在项目中添加NuGet包源执行包还原操作时报错,已添加的源状态显示为UN-REACHABLE,问题截图如下:
问题截图
咨询该问题的触发原因、NuGet源显示不可访问的根由,以及可行修复方案。

问题根因

17.3 build 198属于早期预览版本,内置的NuGet 6.0.0.262在MacOS 12.x环境下存在已知网络栈适配bug,触发UN-REACHABLE报错通常为三类直接原因:

  • 预览版NuGet客户端未正确读取系统代理配置,所有经过代理的包源请求会直接判定为连接失败
  • 包源地址配置时误带尾部多余斜杠、复制时混入不可见特殊字符,该预览版的地址校验逻辑未做容错处理,直接判定地址无效
  • 本地NuGet配置文件目录权限异常,客户端无法写入源连接缓存,误将源标记为不可达
修复方案

按优先级依次尝试,多数场景前两步即可解决问题:

  1. 重置NuGet缓存与目录权限
    完全退出Visual Studio,打开终端执行以下命令:
    chmod -R 700 ~/.config/NuGet/
    rm -rf ~/.local/share/NuGet/http-cache/
    
    执行完成后重启VS,重新添加包源检查状态。
  2. 校验包源地址格式
    添加包源时确认地址末尾无多余/,官方nuget.org源直接使用https://api.nuget.org/v3/index.json,不要使用旧版v2协议地址。如果是内网私有源,先临时关闭系统代理,在浏览器中直接访问源地址确认服务本身可正常连通,再填入VS配置。
  3. 绕开预览版bug完成包还原
    前两步无效则为该预览版本的原生bug,无需纠结VS界面的状态标记:先在终端执行dotnet nuget list source确认命令行环境下源状态正常,进入项目目录直接执行dotnet restore即可完成包还原,不影响后续编译运行。也可以直接升级到17.3正式版或回退到17.2稳定版,该bug在后续预览补丁及正式版本中已完成修复。
  4. 重置VS NuGet配置
    以上操作均无效时,关闭Visual Studio,进入~/Library/VisualStudio/目录找到对应17.3预览版的配置文件夹,删除其中所有NuGet相关配置文件,重启VS后重新配置包源即可。

问题环境详情

Visual Studio Community 2022 for Mac Preview
Version 17.3 Preview (17.3 build 198)
Installation UUID: 45fdd716-7df5-4abb-8cb2-3790ad5defa5

Runtime
.NET 6.0.3 (64-bit)
Architecture: X64

Roslyn (Language Service)
4.2.0-3.22181.8+a59a22c6f3c2cc1883e20cece412209f18f4a29f

NuGet
Version: 6.0.0.262

.NET SDK (x64)
SDK: /usr/local/share/dotnet/sdk/6.0.300/Sdks
SDK Versions:
    6.0.300
    5.0.407
    3.1.419
    3.1.418
MSBuild SDKs: /usr/local/share/dotnet/sdk/6.0.300/Sdks

.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    6.0.5
    5.0.16
    3.1.25
    3.1.24

Xamarin.Profiler
Version: 1.8.0.19
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Apple Developer Tools
Xcode 13.4.1 (20504)
Build 13F100

Xamarin.Mac
Version: 8.10.0.1 (Visual Studio Community)
Hash: 568bdb24e
Branch: d17-2
Build date: 2022-04-08 18:52:56-0400

Xamarin.iOS
Version: 15.10.0.1 (Visual Studio Community)
Hash: 568bdb24e
Branch: d17-2
Build date: 2022-04-08 18:52:57-0400

Xamarin Designer
Version: 17.3.0.70
Hash: 4cf1a2208
Branch: remotes/origin/d17-3
Build date: 2022-05-25 15:23:36 UTC

Xamarin.Android
Version: 12.3.99.58 (Visual Studio Community)
Commit: xamarin-android/main/64b22fc
Android SDK: /Users/divyeshbhatt/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        12.0 (API level 31)
        11.0 (API level 30)

SDK Command-line Tools Version: 5.0
SDK Platform Tools Version: 31.0.3
SDK Build Tools Version: 30.0.3

Build Information: 
Mono: adf1bc4
Java.Interop: xamarin/java.interop/release/6.0.3xx@2a882d2d
ProGuard: Guardsquare/proguard/v7.0.1@912d149
SQLite: xamarin/sqlite/3.38.2@7b1e016
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@fc3c2ac

Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.12
Android Designer EPL code available here

Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here

Android SDK Manager
Version: 17.2.0.47
Hash: d6dd135
Branch: remotes/origin/dev/tondat/main-1512059~2
Build date: 2022-05-25 15:23:29 UTC

Android Device Manager
Version: 0.0.0.1127
Hash: 4bb4d48
Branch: remotes/origin/dev/tondat/main-1536295~1
Build date: 2022-05-25 15:23:29 UTC

Build Information
Release ID: 1703000198
Git revision: b61a5879556b3b4d5270ffffd9431e5ec7db233d
Build date: 2022-05-25 15:21:16+00
Build branch: release-17.3
Build lane: release-17.3

Operating System
Mac OS X 12.3.1
Darwin 21.4.0 Darwin Kernel Version 21.4.0
    Fri Mar 18 00:45:05 PDT 2022
    root:xnu-8020.101.4~15/RELEASE_X86_64 x86_64

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.30 13:42:21