© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
20 replies
Godziak

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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Can't restore public nuget packages while building docker image
C#CC# / help
3y ago
Nuget packages
C#CC# / help
15mo ago
Source Generators In Nuget Packages
C#CC# / help
3y ago
Decoupling Nuget Packages from .csproj for Docker Optimization
C#CC# / help
3y ago