Proxy 使用公司代理时,dotnet还原失败

Proxy 使用公司代理时,dotnet还原失败,proxy,.net-core,centos7,restore,Proxy,.net Core,Centos7,Restore,我刚刚升级到dotnetcore2.1,但dotnetrestore失败了。出于某种原因,它没有使用http\U代理或https\U代理设置。同时提供具有正确代理设置的nuget配置文件也没有帮助 $ dotnet --info .NET Core SDK (reflecting any global.json): Version: 2.1.300 Commit: adab45bf0c Runtime Environment: OS Name: rhel OS Ver

我刚刚升级到dotnetcore2.1,但dotnetrestore失败了。出于某种原因,它没有使用http\U代理或https\U代理设置。同时提供具有正确代理设置的nuget配置文件也没有帮助

$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.1.300
 Commit:    adab45bf0c

Runtime Environment:
 OS Name:     rhel
 OS Version:  7
 OS Platform: Linux
 RID:         rhel.7-x64
 Base Path:   /usr/share/dotnet/sdk/2.1.300/

Host (useful for support):
  Version: 2.1.0
  Commit:  caa7b7e2ba

.NET Core SDKs installed:
  2.1.300 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
错误是:

gitlab-runner@ctxglc-vn02 $ dotnet restore -v n --configfile ~/NuGet.Config
Build started 6/12/18 2:15:05 PM.
     1>Project "/home/gitlab-runner/builds/046a2bda/0/Project/ProjectApi/src/API/API.csproj" on node 1 (Restore target(s)).
     1>Restore:
         Restoring packages for /home/gitlab-runner/builds/046a2bda/0/Project/ProjectApi/src/API/API.csproj...
     1>/usr/share/dotnet/sdk/2.1.300/NuGet.targets(114,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/home/gitlab-runner/builds/046a2bda/0/Project/ProjectApi/src/API/API.csproj]
/usr/share/dotnet/sdk/2.1.300/NuGet.targets(114,5): error :   The SSL connection could not be established, see inner exception. [/home/gitlab-runner/builds/046a2bda/0/Project/ProjectApi/src/API/API.csproj]
/usr/share/dotnet/sdk/2.1.300/NuGet.targets(114,5): error :   error:2006D002:BIO routines:BIO_new_file:system lib [/home/gitlab-runner/builds/046a2bda/0/Project/ProjectApi/src/API/API.csproj]
     1>Done Building Project "/home/gitlab-runner/builds/046a2bda/0/Project/ProjectApi/src/API/API.csproj" (Restore target(s)) -- FAILED.

Build FAILED.

       "/home/gitlab-runner/builds/046a2bda/0/Project/ProjectApi/src/API/API.csproj" (Restore target) (1) ->
       (Restore target) ->
         /usr/share/dotnet/sdk/2.1.300/NuGet.targets(114,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [/home/gitlab-runner/builds/046a2bda/0/Project/ProjectApi/src/API/API.csproj]
       /usr/share/dotnet/sdk/2.1.300/NuGet.targets(114,5): error :   The SSL connection could not be established, see inner exception. [/home/gitlab-runner/builds/046a2bda/0/Project/ProjectApi/src/API/API.csproj]
       /usr/share/dotnet/sdk/2.1.300/NuGet.targets(114,5): error :   error:2006D002:BIO routines:BIO_new_file:system lib [/home/gitlab-runner/builds/046a2bda/0/Project/ProjectApi/src/API/API.csproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.84
然而,当我做卷曲时,我可以毫无问题地连接

$ curl -v https://api.nuget.org/v3/index.json
* About to connect() to proxy proxy.company.local port 8080 (#0)
*   Trying 1.1.1.1...
* Connected to proxy.company.local (1.1.1.1) port 8080 (#0)
* Establish HTTP proxy tunnel to api.nuget.org:443
> CONNECT api.nuget.org:443 HTTP/1.1
> Host: api.nuget.org:443
> User-Agent: curl/7.29.0
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 Connection established
$curl-vhttps://api.nuget.org/v3/index.json
*即将连接()到proxy.company.local端口8080(#0)
*正在尝试1.1.1.1。。。
*已连接到proxy.company.local(1.1.1.1)端口8080(#0)
*建立HTTP代理隧道到api.nuget.org:443
>connectapi.nuget.org:443http/1.1
>主持人:api.nuget.org:443
>用户代理:curl/7.29.0
>代理连接:保持活动状态
>

关于如何克服此问题的任何提示?

如果您使用的是VS代码,请尝试在VS代码用户设置中添加代理设置:

"http.proxy": "https://company-proxy:3128",
"http.proxyStrictSSL": false,
如果是nuget配置,请尝试以下操作-

nuget.exe config -set http_proxy=http://my.proxy.address:port
nuget.exe config -set http_proxy.user=mydomain\myUserName
nuget.exe config -set http_proxy.password=mySuperSecretPassword
或者尝试在nuget配置文件中进行更改-

<configuration>
<!-- stuff -->
<config>
    <add key="http_proxy" value="http://my.proxy.address:port" />
    <add key="http_proxy.user" value="mydomain\myUserName" />
    <add key="http_proxy.password" value="base64encodedHopefullyEncryptedPassword" />
</config>
<!-- stuff -->


因为使用了CentOS7中位于/etc/pki/tls/certs/下的CA目录。在dotnet生成/还原期间,将加载此目录中的所有证书(*.crt)

在我的情况下,一个证书没有正确的权限

chmod o+r /etc/pki/tls/certs/some_cert.crt

修复了非root用户的dotnet构建。

谢谢,但这是CA证书存储的权限问题。错误“error:2006D002:BIO例程:BIO_new_文件”提示了这一点。我仍然需要弄清楚要设置什么样的确切权限。