Godziak
Godziak
CC#
Created by Godziak on 7/29/2023 in #help
Nuget packages won't restore properly when building in docker when using custom nuget feed
I have a custom NuGet package feed, and everything works when I build the application locally using VS or dotnet build. However, when I build the same project in Docker, it fails with the error: The type or namespace name 'ImageApi' could not be found (are you missing a using directive or an assembly reference?) The Dockerfile looks like this:
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["Aero.InternalApi.WebApi/Aero.InternalApi.WebApi.csproj", "Aero.InternalApi.WebApi/"]
COPY ["Aero.Common/Aero.Common.csproj", "Aero.Common/"]
COPY ["Aero.InternalApi.DAL/Aero.InternalApi.DAL.csproj", "Aero.InternalApi.DAL/"]
COPY ["Aero.InternalApi.DTO/Aero.InternalApi.DTO.csproj", "Aero.InternalApi.DTO/"]
COPY ["Aero.InternalApi.Services/Aero.InternalApi.Services.csproj", "Aero.InternalApi.Services/"]
RUN dotnet nuget add source https://<mydomain>/v3/index.json
RUN dotnet restore "Aero.InternalApi.WebApi/Aero.InternalApi.WebApi.csproj"
COPY . .
WORKDIR "/src/Aero.InternalApi.WebApi"
RUN dotnet build "Aero.InternalApi.WebApi.csproj" -c Release -o /app/build
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["Aero.InternalApi.WebApi/Aero.InternalApi.WebApi.csproj", "Aero.InternalApi.WebApi/"]
COPY ["Aero.Common/Aero.Common.csproj", "Aero.Common/"]
COPY ["Aero.InternalApi.DAL/Aero.InternalApi.DAL.csproj", "Aero.InternalApi.DAL/"]
COPY ["Aero.InternalApi.DTO/Aero.InternalApi.DTO.csproj", "Aero.InternalApi.DTO/"]
COPY ["Aero.InternalApi.Services/Aero.InternalApi.Services.csproj", "Aero.InternalApi.Services/"]
RUN dotnet nuget add source https://<mydomain>/v3/index.json
RUN dotnet restore "Aero.InternalApi.WebApi/Aero.InternalApi.WebApi.csproj"
COPY . .
WORKDIR "/src/Aero.InternalApi.WebApi"
RUN dotnet build "Aero.InternalApi.WebApi.csproj" -c Release -o /app/build
It doesn't show any errors during the restore. I also tried restoring directly for Aero.InternalApi.Services, also without any errors. It fails only during the build. Does anyone have any idea how can i fix this or have encountered something similar?
21 replies