Dockerfile COPY 后缺少 .csproj 文件

问题描述 投票:0回答:1

我有以下文件结构:

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

我的 docker 文件看起来像这样

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"]

我的问题是,在运行 dotnet Restore 时,我收到以下错误消息,表明该项目丢失。我尝试更改文件结构和其他一些操作,例如复制 sln 并从中恢复,但没有任何效果对我有用。

[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
c# .net docker dockerfile
1个回答
0
投票

我在 COPY 指令末尾缺少“/”符号

COPY ["./src/MeetingApp.Api/MeetingApp.Api.csproj", "MeetingApp.Api/"]
© www.soinside.com 2019 - 2024. All rights reserved.