dotnet restore出现SSL错误的解决方案

我的博客

博客链接

错误场景

当我把.net core webpai项目部署到centos上后,使用dotnet restore命令还原时,出现如下错误:

image-20220201220500060

/usr/share/dotnet/sdk/5.0.404/NuGet.targets(131,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/root/stickynotesbackend/CloudWorking/CloudWorkingBackend/CloudWorkingBackend.sln]
/usr/share/dotnet/sdk/5.0.404/NuGet.targets(131,5): error :   The SSL connection could not be established, see inner exception. [/root/stickynotesbackend/CloudWorking/CloudWorkingBackend/CloudWorkingBackend.sln]
/usr/share/dotnet/sdk/5.0.404/NuGet.targets(131,5): error :   The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot [/root/stickynotesbackend/CloudWorking/CloudWorkingBackend/CloudWorkingBackend.sln]

实际上在出现这个错误的时候是因为我在jenkins里面用dotnet restore命令时报出来的,坑爹的花了我3个小时才解决

错误原因

大概原因是https证书找不到,所以没有权限调接口拉数据下来

解决方案

查询openssl的路径:

openssl version -a		

img

然后将 CentOS 默认的 openssl CA 证书拷贝到 OPENSSLDIR

cp /etc/pki/tls/cert.pem /usr/local/openssl/

然后再次运行dotnet restore:

image-20220201220744924

其他解决方案

实际上上面的解决方案是我找了3个小时左右最后才成功的,如果试过了还不行,可以参考下面的这些博客或链接的思路:

  1. 博客1

  2. 微软官方的方案,注意系统是windows还是linux(ubuntu、centos不是一样的,注意)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值