Symptom

Offline NuGet package is missing in Docker.


Resolution

1. Copy the NuGet offline package file to the NuGetPackage folder (create it if it does not exist) at the root folder of C# Solution.

Copy the NuGet offline package


2. In your Docker file, add the following red part to the file to add the offline package as a NuGet source. So the docker restore can find the new package.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["ServerAPIs/ServerAPIs.csproj", "ServerAPIs/"]
COPY ["AppModels/AppModels.csproj", "AppModels/"]
COPY ["UserExtensions/UserExtensions.csproj", "UserExtensions/"]

COPY ["NuGetPackage", "/NuGetPackage"] 
RUN  dotnet NuGet add source /NuGetPackage -n  PackageHotfix

RUN dotnet restore "ServerAPIs/ServerAPIs.csproj"
COPY . .
WORKDIR "/src/ServerAPIs"
RUN dotnet build "ServerAPIs.csproj" -c Release -o /app/build

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

FROM base AS final

WORKDIR /app
COPY --from=publish /app/ publish .
ENTRYPOINT ["dotnet", "ServerAPIs.dll"]


3. Publish your docker image.
 

1
0