Muhammad Nasir
Muhammad Nasir

Reputation: 2204

Docker build for ASP.NET Core 8 return error Program does not contain a static 'Main' method suitable for an entry point

I want to create a Docker image for my ASP.NET Core 8 application. The Dockerfile must be located in the root directory of the git repository, as shown in the attached image. When I place the Dockerfile inside the API project, everything works fine, but I need to keep it in the application's root directory.

enter image description here

Here is my dockerfile:

#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["LibraryApp/*.sln", "./"]
COPY ["LibraryApp/LibraryApp.Api/LibraryApp.Api.csproj", "LibraryApp.Api/"]
COPY ["LibraryApp/LibraryApp.Dtos/LibraryApp.Dtos.csproj", "LibraryApp.Dtos/"]
COPY ["LibraryApp/LibraryApp.Infrastructure/LibraryApp.Infrastructure.csproj", "LibraryApp.Infrastructure/"]
COPY ["LibraryApp/LibraryApp.Services/LibraryApp.Services.csproj", "LibraryApp.Services/"]
RUN dotnet restore "./LibraryApp.sln"

RUN dotnet restore "./LibraryApp.Api/LibraryApp.Api.csproj"
COPY . .

WORKDIR "/src/LibraryApp.Api"
RUN dotnet build "./LibraryApp.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build
#RUN dotnet publish -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./LibraryApp.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

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

when I build it using docker build -t libraryapp. i am getting error.

>  => ERROR [build 12/12] RUN dotnet build "./LibraryApp.Api.csproj" -c
> Release -o /app/build                                                 
> 10.6s
> ------
>  > [build 12/12] RUN dotnet build "./LibraryApp.Api.csproj" -c Release -o /app/build:
> 1.836   Determining projects to restore...
> 3.474   All projects are up-to-date for restore.
> 8.368   LibraryApp.Dtos -> /app/build/LibraryApp.Dtos.dll
> 8.416   LibraryApp.Infrastructure -> /app/build/LibraryApp.Infrastructure.dll
> 8.999   LibraryApp.Services -> /app/build/LibraryApp.Services.dll
> 10.46 CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point
> [/src/LibraryApp.Api/LibraryApp.Api.csproj]
> 10.48
> 10.49 Build FAILED.
> 10.49
> 10.49 CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point
> [/src/LibraryApp.Api/LibraryApp.Api.csproj]
> 10.49     0 Warning(s)
> 10.49     1 Error(s)
> 10.49
> 10.49 Time Elapsed 00:00:09.70
> ------ WARNING: current commit information was not captured by the build: git was not found in the system: exec: "git.exe": executable
> file not found in %PATH% Dockerfile:23
> --------------------   21 |   22 |     WORKDIR "/src/LibraryApp.Api"   23 | >>> RUN dotnet build "./LibraryApp.Api.csproj" -c
> $BUILD_CONFIGURATION -o /app/build   24 |     #RUN dotnet publish -c
> $BUILD_CONFIGURATION -o /app/build   25 |
> -------------------- ERROR: failed to solve: process "/bin/sh -c dotnet build \"./LibraryApp.Api.csproj\" -c $BUILD_CONFIGURATION -o
> /app/build" did not complete successfully: exit code: 1

enter image description here

I have tried everything and searched a lot but have not been able to fix it.

Anything that helps me resolve this issue would be appreciated.

Thanks

Upvotes: 1

Views: 102

Answers (0)

Related Questions