Home > other >  Failed to restore packages on docker using dotnet 7 SDK
Failed to restore packages on docker using dotnet 7 SDK

Time:01-24

I'm trying to figure it out for a few days now and to be honest I am completely blocked and I have no idea why is it failing.

The whole API is just a controller with nothing in it really, just a test for the docker and dotnet versions.

Reference files:

    // webapp csproj

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
    </PropertyGroup>
# Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src

COPY . .

RUN dotnet publish src/WebApp/WebApp.csproj -c Release -o release/

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

COPY --from=build src/release .

ENV ASPNETCORE_URLS "http://*:80"
EXPOSE 80
ENTRYPOINT [ "dotnet", "WebApp.dll" ]

The issue:

If I update net6.0 to net7.0 on the webapp project and dockerfile for the respective sdk/aspnetcore I start getting a bunch of nuget errors.

/usr/share/dotnet/sdk/7.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(267,5): warning NETSDK1004: Assets file '/root/.nuget/packages/system.threading.channels/4.7.1/lib/netcoreapp3.0/System.Threading.Channels.xml' not found. Run a NuGet package restore to generate this file. [/src/src/WebApp/WebApp.csproj]

Basically assets file not found error but I have no idea why it fails when the dotnet version changes, I'm assuming something changed and I'm not doing part of the configuration/setup or copying something that dotnet 7 needs and dotnet 6 sort of does automatically but I'm already at the end of a room and I can't seem to find the way out.

I read release notes, read the github examples and tried to the same structure as "add docker support" option directly on visual studio.

Locally everything works. I have no private nuget sources and I tried to clean my local cache just in case.

Registered Sources:
  1.  nuget.org [Enabled]
      https://api.nuget.org/v3/index.json
  2.  Microsoft Visual Studio Offline Packages [Enabled]
      C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

I have no idea what I'm missing.

CodePudding user response:

I'm wondering if you're copying in the bin and obj directories from your host machine into the container via COPY . .. That will mess up the restore. Do you have a .dockerignore file defined at all? It should be configured to filter out those directories. For example: https://github.com/dotnet/dotnet-docker/blob/da1264a67e4a9fe2cafd4958ec82f59749d97106/.dockerignore#L1-L2

  • Related