I have a problem and I want to create a docker for an ASP.NET Core 6 Web API, the library does not have a main function so it still has an error when running the build:
#20 6.813 CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/src/api/Jalasoft.Dev33Level2.Programs.Api/Jalasoft.Dev33Level2.Programs.Api.csproj]
The program.cs is different because I use the .NET 6 SDK, as I knew it before so if it does not have a main function:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
Now the docker I use is the following, I use this and the .NET 6 SDK is what causes the error possibly:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
# copy csproj and restore as distinct layers
COPY Programs/*.sln ./
COPY Programs/src/api/Programs.Api/*.csproj ./src/api/Programs.Api/
COPY Programs/src/core/Programs.Service/*.csproj ./src/core/Programs.Service/
RUN dotnet restore
COPY . ./
RUN dotnet build -c Release -o /src/build
FROM build AS publish
RUN dotnet publish -c Release -o /src/publish --no-restore
FROM base AS final
WORKDIR /app
COPY --from=publish /src/publish .
ENTRYPOINT ["dotnet", "Jalasoft.Dev33Level2.Programs.Api.dll"]