C
C#•17mo ago
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?
12 Replies
Becquerel
Becquerel•17mo ago
Have you tried creating a nuget.config file that is copied into the container (should be picked up automatically by dotnet restore, but you can also use dotnet restore --configfile yourfilehere.config) You can also try running dotnet restore --verbosity detailed foobar.csproj to get more info I had similar issues to this a while ago at work and it was ultimately due to our corporate proxy, incidentally
Godziak
GodziakOP•17mo ago
I will try that and let you know 🙂 thanks
Becquerel
Becquerel•17mo ago
no prob
Godziak
GodziakOP•17mo ago
Well - during the 'dotnet restore' command - i saw that the https://<mydomain>/v3/index.json was being searched for all the packages (I've added it in the nuget.config above the nuget.org) - and everything seemed to work fine. The packages that were not present in my nuget feed were later searched for in the nuget.org feed - altho the ones that should've been downloaded from my feed seemed to be searched for again later on. However, in the log there were parts such as 'Installed ImageApi.DTO from mynugetfeed [...]' and so on. As I would prefer not to share publicly my domain I can send you the relevant logs directly if you would like to take a look 🙂
Becquerel
Becquerel•17mo ago
that's curious but makes me think it might not be a nuget issue at all i'm assuming the error you get which mentions 'ImageApi', that's the actual name of your solution, not 'InternalApi' i remember back when i set up a project which had dependencies on other projects in docker a while back it required some slightly unintuitive work with the build context
Godziak
GodziakOP•17mo ago
the ImageApi is the name of the nuget package
Becquerel
Becquerel•17mo ago
did you write this dockerfile yourself, or generate it in VS? oh, I see
Godziak
GodziakOP•17mo ago
yep, and I wrote it myself
Becquerel
Becquerel•17mo ago
i'd try having VS/rider generate it to see if there's any material difference i'm open to looking over the logs, though no promises i can find anything in them ironic the verbosity on dotnet build might also be useful
Godziak
GodziakOP•17mo ago
will see and let you know whats up 😄 will dm you with the logs etc. in a sec
Mayor McCheese
Mayor McCheese•17mo ago
Do you need to authenticate to the feed?
Godziak
GodziakOP•17mo ago
nope alr. i gave up and just moved required project over to my current solution
Want results from more Discord servers?
Add your server