我尝试使用Visual Studio从后端项目创建发行版本,但收到错误消息

服务'backend_api'生成失败:命令'/ bin / sh -c dotnet build ...

使用“docker-compose build”,我得到相同的错误。

在Visual Studio的 Debug模式下,它可以工作。

Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
WORKDIR /src
COPY ["backendAPI/backendAPI.csproj", "backendAPI/"]
RUN dotnet restore "backendAPI/backendAPI.csproj"
COPY . .
WORKDIR "/src/backend_API"
RUN dotnet build "backendAPI.csproj" -c Release -o /app/build

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

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

docker-compose.yml
version: '3.7'

services:
  backend_sql:
    image: mcr.microsoft.com/mssql/server:2017-GA-ubuntu
    container_name: testsql
    networks:
      - test_network
    ports:
      - "1440:1433"
    volumes:
     - testsqldata:/var/opt/mssql

  backend_api:
    image: ${DOCKER_REGISTRY-}backendapi
    container_name: testapi
    build:
      context: .
      dockerfile: backendAPI/Dockerfile
    networks:
      - test_network
    depends_on:
     - backend_sql
    ports:
     - "5000:80"

networks:
  test_network:
    external:
        name: test_network

volumes:
  testsqldata:
    driver: local
    name: testsqldata

错误消息:
...
2>Step 7/16 : RUN dotnet restore "backendAPI/backendAPI.csproj"
2> ---> Running in ee20ee70cedf
2>  Restore completed in 41.8 sec for /src/backendAPI/backendAPI.csproj.
2>Removing intermediate container ee20ee70cedf
2> ---> 6cafbb7f9daf
2>Step 8/16 : COPY . .
2> ---> 74dc0dfe8145
2>Step 9/16 : WORKDIR "/src/backend_API"
2> ---> Running in e198c3ffb356
2>Removing intermediate container e198c3ffb356
2> ---> 114bfbba3151
2>Step 10/16 : RUN dotnet build "backendAPI.csproj" -c Release -o /app/build
2> ---> Running in 3e7bf02253ce
2>Microsoft (R) Build Engine version 16.3.2+e481bbf88 for .NET Core
2>Copyright (C) Microsoft Corporation. All rights reserved.
2>MSBUILD : error MSB1009: Project file does not exist.
2>Switch: backendAPI.csproj
2>Service 'backend_api' failed to build: The command '/bin/sh -c dotnet build "backendAPI.csproj" -c Release -o /app/build' returned a non-zero code: 1
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(492,5): error DT1001: Service 'backend_api' failed to build: The command '/bin/sh -c dotnet build "backendAPI.csproj" -c Release -o /app/build' returned a non-zero code: 1
2>Done building project "docker-compose.dcproj" -- FAILED.

最佳答案



此错误表明当前位置没有这样的*.proj文件。发生这种情况是因为您拼写了错误的路径:应该是backendAPI而不是backend_API。要解决此问题,请按如下所示更改代码:

从mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS构建
WORKDIR / src
COPY [“backendAPI / backendAPI.csproj”,“backendAPI /”]
运行dotnet还原“backendAPI / backendAPI.csproj”
复制。 。
WORKDIR“/ src / backend_API”
WORKDIR“/ src / backendAPI”
RUN dotnet构建“backendAPI.csproj” -c版本-o / app / build

07-28 04:02