我正在尝试在 Docker (Linux) 上为企业代理后面的 .NET 6 应用程序下载 NuGet 包
ARG netVersion=6.0
FROM mcr.microsoft.com/dotnet/sdk:${netVersion} AS build-env
WORKDIR /app
COPY company-root-ca.crt /usr/local/share/ca-certificates/company-root-ca.crt
RUN update-ca-certificates
COPY App/*.csproj .
RUN dotnet restore --configfile nuget.config
The dotnet restore
调用失败:
#17 [build-env 10/18] RUN dotnet restore --configfile nuget.config
#17 1.083 Determining projects to restore...
#17 6.883 /app/MyApp.csproj : error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json.
#17 6.900 /usr/share/dotnet/sdk/6.0.301/NuGet.targets(130,5): error : Sequence contains no elements [/app/MyApp.csproj]
#17 ERROR: executor failed running [/bin/sh -c dotnet restore --configfile nuget.config]: exit code: 1
------
> [build-env 10/18] RUN dotnet restore --configfile nuget.config:
#17 1.083 Determining projects to restore...
#17 6.883 /app/MyApp.csproj : error NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json.
#17 6.900 /usr/share/dotnet/sdk/6.0.301/NuGet.targets(130,5): error : Sequence contains no elements [/app/MyApp.csproj]
RUN curl https://api.nuget.org/v3/index.json
在容器中工作正常,因此使用我们的代理的互联网连接不是问题(它是使用构建参数设置的)。ENV DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0
似乎没有任何效果,就像nuget.config
在不同的类似问题/票证中建议的文件:
<configuration>
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy usesystemdefault="true" bypassonlocal="true" />
</defaultProxy>
<settings>
<ipv6 enabled="true"/>
</settings>
</system.net>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<!--
<activePackageSource>
<add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</activePackageSource>
-->
</configuration>
一些参考:
- https://stackoverflow.com/a/42207912/9428314 https://stackoverflow.com/a/42207912/9428314
- https://stackoverflow.com/a/49921024/9428314 https://stackoverflow.com/a/49921024/9428314
- Docker 无法加载源 https://api.nuget.org/v3/index.json 的服务索引 https://stackoverflow.com/questions/50347517/docker-unable-to-load-the-service-index-for-source-https-api-nuget-org-v3-inde/57524133#57524133
我能够通过添加个人访问令牌 (PAT) 作为工件源的密码来解决此问题。
Example:
# access token arg is passed in by build process
ARG ACCESS_TOKEN="your PAT"
ARG ARTIFACTS_ENDPOINT="https://yoursource/v3/index.json"
# Configure the environment variables
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS "{\"endpointCredentials\": [{\"endpoint\":\"${ARTIFACTS_ENDPOINT}\", \"password\":\"${ACCESS_TOKEN}\"}]}"
我还需要终端以管理员权限运行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)