我正在尝试构建docker镜像,但是在尝试从私有(private)Nuget Feed恢复Nuget包时却出现此错误。我已经尝试了来自互联网的许多解决方案。到目前为止没有任何工作。请帮忙。

我的Docker File看起来像这样:-

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["Api/Api.csproj", "Api/"]
COPY ["Persistence.EntityFramework/Nuget.config", "Persistence.EntityFramework/"]
COPY ["Contracts/Contracts.csproj", "Contracts/"]
COPY ["Persistence/Persistence.csproj", "Persistence/"]
COPY ["Domain/Domain.csproj", "Domain/"]
COPY ["Handlers/Handlers.csproj", "Handlers/"]
COPY ["Localisation/Localisation.csproj", "Localisation/"]
COPY ["Persistence.EntityFramework/Persistence.EntityFramework.csproj", "Persistence.EntityFramework/"]
RUN dotnet restore "Persistence.EntityFramework/Persistence.EntityFramework.csproj" --configfile "Persistence.EntityFramework/Nuget.config"
RUN dotnet restore "Api/Api.csproj"
COPY . .
WORKDIR "/src/Api"
RUN dotnet build "Api.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "Api.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Security.Api.dll"]

我的Nuget.Config看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageRestore>
    <!-- Allow NuGet to download missing packages -->
    <add key="enabled" value="True" />
    <!-- Automatically check for missing packages during build in Visual Studio -->
    <add key="automatic" value="True" />
  </packageRestore>
  <packageSources>
    <add key="NuGet.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="companyname" value="http://vnuget.companyname.com/privateNugetFeed/nuget/Packages"/>
  </packageSources>
</configuration>

这是我们看到的错误:
Retrying 'FindPackagesByIdAsyncCore' for source 'http://vnuget.companyname.com/privateNugetFeed/nuget/Packages/FindPackagesById()?id='Microsoft.EntityFrameworkCore.Relational'&semVerLevel=2.0.0'.
[15:44:36][Step 3/7]   Response status code does not indicate success: 400 (Bad Request).

最佳答案

嗨,我发现了问题..

我的Nuget配置文件中的Package Source链接不正确

它应该是 :-

 <add key="companyname" value="http://vnuget.companyname.com/privateNugetFeed/nuget"/>

这已经解决了这个问题, docker 现在正在正确构建!

关于docker - 从私有(private)nuget feed恢复nuget包-Docker给出错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57311788/

10-16 02:11