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

已启用TLS12仍无法在Docker中安装NuGet包提供程序

解决Windows Server Core LTSC2019容器中安装NuGet包管理器失败的问题

针对你在mcr.microsoft.com/windows/servercore:ltsc2019镜像中执行Install-PackageProvider -Name NuGet -Force时出现的下载失败、找不到提供者问题,即使已设置TLS12仍无法解决,可尝试以下几种实用方案:

方案1:手动下载并安装NuGet Provider

默认的提供者列表链接在容器环境中可能存在访问或证书验证异常,可直接下载NuGet Provider包进行本地安装:

在Dockerfile中添加以下命令:

RUN powershell -Command \
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    Invoke-WebRequest -Uri 'https://www.nuget.org/api/v2/package/NuGet.PackageManagement/2.8.5.208' -OutFile 'NuGetProvider.nupkg'; \
    Install-PackageProvider -Path .\NuGetProvider.nupkg -Force; \
    Remove-Item .\NuGetProvider.nupkg

选择2.8.5.208版本是因为它与PowerShell 5.1兼容性较好,也可根据需求选择更高的兼容版本。

方案2:指定安装源并临时跳过证书验证(仅测试用)

如果是证书验证导致的问题,可临时跳过证书检查并指定NuGet官方源:

RUN powershell -Command \
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }; \
    Install-PackageProvider -Name NuGet -Force -Source 'https://www.nuget.org/api/v2/'; \
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null

注意:此方法会跳过证书验证,仅建议用于测试环境,生产环境不推荐使用。

方案3:更新容器内的根证书

Windows Server Core LTSC2019的根证书可能过期,导致无法验证HTTPS站点的证书。可通过导入最新根证书解决:

  1. 获取适用于Windows Server 2019的最新根证书更新包
  2. 将证书文件复制到容器内,执行安装命令:
RUN powershell -Command \
    certutil -addstore -f root .\root_certs.cer

(替换.\root_certs.cer为实际的证书文件路径)

方案4:检查容器网络连通性

确保容器能正常访问外部网络,可在Dockerfile中添加测试命令:

RUN powershell -Command ping nuget.org

如果无法ping通,需检查Docker的网络配置,确保容器有权限访问外部网络。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 03:31:33