我的博客
错误场景
当我把.net core webpai项目部署到centos上后,使用dotnet restore
命令还原时,出现如下错误:
/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
然后将 CentOS 默认的 openssl CA 证书拷贝到 OPENSSLDIR
cp /etc/pki/tls/cert.pem /usr/local/openssl/
然后再次运行dotnet restore
:
其他解决方案
实际上上面的解决方案是我找了3个小时左右最后才成功的,如果试过了还不行,可以参考下面的这些博客或链接的思路: