Search code examples
c#.netdockerdockerfile

Missing .csproj file after Dockerfile COPY


I have following file structure:

-- Dockefile
-- MeetingApp.sln
-- src
   -- MeetingApp.Api
      -- MeetingApp.Api.csproj
   -- <other related projects>

And my docker file looks like this

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
ENV ASPNETCORE_URLS=https://+:7001;http://+:7000
EXPOSE 7000
EXPOSE 7001

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["./src/MeetingApp.Api/MeetingApp.Api.csproj", "MeetingApp.Api"]
COPY ["./src/MeetingApp.Application/MeetingApp.Application.csproj", "MeetingApp.Application"]
COPY ["./src/MeetingApp.Contracts/MeetingApp.Contracts.csproj", "MeetingApp.Contracts"]
COPY ["./src/MeetingApp.Domain/MeetingApp.Domain.csproj", "MeetingApp.Domain.Api"]
COPY ["./src/MeetingApp.EntityFramework/MeetingApp.EntityFramework.csproj", "MeetingApp.EntityFramework"]
COPY ["./src/MeetingApp.Infrastructure/MeetingApp.Infrastructure.csproj", "src/MeetingApp.Infrastructure"]

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

FROM build AS publish
RUN dotnet publish "MeetingApp.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false --no-restore

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MeetingApp.Api.dll"]

My problem is that on RUN dotnet restore I get the following error message indicating that the project is missing. I tried changing file structure and some other things like copying the sln and restoring from it but nothing has worked for me.

[build  9/12] RUN dotnet restore "MeetingApp.Api/MeetingApp.Api.csproj":
0.626 MSBUILD : error MSB1009: Project file does not exist.
0.626 Switch: MeetingApp.Api/MeetingApp.Api.csproj
------
Dockerfile:16
--------------------
  14 |     COPY ["./src/MeetingApp.Infrastructure/MeetingApp.Infrastructure.csproj", "src/MeetingApp.Infrastructure"]
  15 |
  16 | >>> RUN dotnet restore "MeetingApp.Api/MeetingApp.Api.csproj"
  17 |     COPY . .
  18 |     WORKDIR "src/MeetingApp.Api"
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet restore \"MeetingApp.Api/MeetingApp.Api.csproj\"" did not complete successfully: exit code: 1

Solution

  • I was missing the '/' symbol in the end of COPY instruction

    COPY ["./src/MeetingApp.Api/MeetingApp.Api.csproj", "MeetingApp.Api/"]