4

I try to create a release build from my backend project with the Visual Studio, but I get the error message

Service 'backend_api' failed to build: The command '/bin/sh -c dotnet build ...

With "docker-compose build" I get the same error.

In Debug-Mode of the Visual Studio it works.

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

Error-Message:

...
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.

1 Answer 1

2

"error MSB1009: Project file does not exist":

This error indicates that there's no such a *.proj file in current location. That happens because you spelled the path incorrectly: it should be backendAPI instead of backend_API. To fix that issue, change your code as below:

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"
WORKDIR "/src/backendAPI"
RUN dotnet build "backendAPI.csproj" -c Release -o /app/build
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.