我尝试在Docker(Linux)上下载NuGet软件包,用于公司代理后面的.NET 6应用程序
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
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/49921024/9428314
- 无法加载控制器:Error到这里去看看https://api.nuget.org/v3/index.json
1条答案
按热度按时间y1aodyip1#
我能够通过添加个人访问令牌(PAT)作为工件源的密码来解决它。
示例:
我还需要终端以管理员权限运行。