C
C#2y ago
NickIndie

❔ Can't restore public nuget packages while building docker image

[build 10/10] RUN dotnet publish -c release -o /app --no-restore: #0 0.362 MSBuild version 17.5.0+6f08c67f3 for .NET #0 0.796 /usr/share/dotnet/sdk/7.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1064: Package Microsoft.Extensions.Logging.Abstractions, version 7.0.0 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.
7 Replies
NickIndie
NickIndieOP2y ago
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY OSRS-TaskAPI/*.csproj ./OSRS-TaskAPI/
COPY OSRS-TaskAPI.Domain/*.csproj ./OSRS-TaskAPI.Domain/
COPY OSRS-TaskAPI.Quests/*.csproj ./OSRS-TaskAPI.Quests/
RUN dotnet restore

# copy everything else and build app
COPY OSRS-TaskAPI/. ./OSRS-TaskAPI/
WORKDIR /source/OSRS-TaskAPI
RUN dotnet publish -c release -o /app --no-restore

# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=build /app ./
ENTRYPOINT ["dotnet", "OSRS-TaskAPI.dll"]
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY OSRS-TaskAPI/*.csproj ./OSRS-TaskAPI/
COPY OSRS-TaskAPI.Domain/*.csproj ./OSRS-TaskAPI.Domain/
COPY OSRS-TaskAPI.Quests/*.csproj ./OSRS-TaskAPI.Quests/
RUN dotnet restore

# copy everything else and build app
COPY OSRS-TaskAPI/. ./OSRS-TaskAPI/
WORKDIR /source/OSRS-TaskAPI
RUN dotnet publish -c release -o /app --no-restore

# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=build /app ./
ENTRYPOINT ["dotnet", "OSRS-TaskAPI.dll"]
NickIndie
NickIndieOP2y ago
I'm learning now that net 7 introduced a microsoft container builder... https://github.com/dotnet/sdk-container-builds
GitHub
GitHub - dotnet/sdk-container-builds: Experimental OCI containers l...
Experimental OCI containers libraries and tasks. Contribute to dotnet/sdk-container-builds development by creating an account on GitHub.
NickIndie
NickIndieOP2y ago
going to mess with that
NickIndie
NickIndieOP2y ago
That's pretty cool.
NickIndie
NickIndieOP2y ago
But I'd still like to know what went wrong.
Anton
Anton2y ago
Some project file might conditionally reference that package based on configuration or some other property, which make dotnet restore not download all packages that are needed for build. After that you're doing a build without restore, but a release build has other constants defined than debug. that's my guess try passing the configuration flag to restore (it supports that, right?) or just remove --no-restorw and the restore before
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server