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

2wnc66cl  于 2022-11-02  发布在  Docker
关注(0)|答案(1)|浏览(917)

我尝试在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>

一些参考资料:

y1aodyip

y1aodyip1#

我能够通过添加个人访问令牌(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}\"}]}"

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

相关问题