0

Im trying to create a docker image of my ASP.net web application, but i get the error "program does not contain a static 'main' method suitable for an entry point" im on .net 6.0 so there is no startup.cs anymore with a main, is there a way i can fix this?

Here the error

My program looks like this: 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 connectionString = builder.Configuration.GetConnectionString("DBConnection");
    builder.Services.AddDbContext<ApplicationDbContext>(x => x.UseSqlServer(connectionString));

    builder.Services.AddCors(options =>
    {
        options.AddPolicy("CorsPolicy", builder =>
            builder.SetIsOriginAllowed(origin => new Uri(origin).Host == "localhost")
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials());
    });

    var app = builder.Build();

    // Configure the HTTP request pipeline.
    if (app.Environment.IsDevelopment())
    {
        app.UseSwagger();
        app.UseSwaggerUI();
    }

    app.UseCors("CorsPolicy");

    app.UseHttpsRedirection();

    app.UseAuthorization();

    app.MapControllers();

    app.Run();

so it has no startup with a static main

my dockerfile looks like this:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["LiveChat-Backend.csproj", "LiveChat-Backend/"]
RUN dotnet restore "LiveChat-Backend/LiveChat-Backend.csproj"
COPY . .
WORKDIR "/src/LiveChat-Backend"
RUN dotnet build "LiveChat-Backend.csproj" -c Release -o /app/build

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

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

my .csproj looks like this:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <RootNamespace>LiveChat_Backend</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.9" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.9" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.9" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.9">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Migrations\" />
  </ItemGroup>

</Project>
Bart
  • 31
  • 3

0 Answers0