Docker 中的 NuGet:错误 NU1301:无法加载源的服务索引 - 序列不包含任何元素

Dan*_*iel 11 .net asp.net docker dockerfile

我正在尝试在 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
Run Code Online (Sandbox Code Playgroud)

调用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 Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

一些参考:

小智 3

我能够通过添加个人访问令牌 (PAT) 作为工件源的密码来解决该问题。

例子:

# 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}\"}]}"
Run Code Online (Sandbox Code Playgroud)

我还需要终端以管理员权限运行。


归档时间:

查看次数:

25268 次

最近记录:

2 年,7 月 前