【发布时间】:2021-11-11 12:37:07
【问题描述】:
我正在尝试构建我的 docker 映像,但出现此错误。
错误 CS5001:程序不包含适用于入口点的静态“Main”方法 [/6GAG.WebApi/6GAG.WebApi.csproj]
我在 1 个解决方案中有 3 个项目。
- 1 个 webapi
- 1 个前端应用程序
- 1个类库
我的 Dockerfile 存在于我的 .sln 文件所在的目录中
FROM mcr.microsoft.com/dotnet/sdk:6.0 as build-env
WORKDIR /app
COPY 6GAG.WebApi/6GAG.WebApi.csproj /6GAG.WebApi/6GAG.WebApi.csproj
COPY 6GAG.Core/6GAG.Core.csproj /6GAG.Core/6GAG.Core.csproj
RUN dotnet restore /6GAG.WebApi/6GAG.WebApi.csproj
COPY ./ ./
RUN dotnet publish /6GAG.WebApi/6GAG.WebApi.csproj -c Release -o out
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
EXPOSE 80
COPY --from=build-env app/out/ .
ENTRYPOINT ["dotnet", "6GAG.WebApi.dll"]
我的 .csproj 文件:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_6GAG.WebApi</RootNamespace>
<UserSecretsId>7f7e2bd0-6f27-4752-afe8-9839b765d3f0</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="FluentValidation.AspNetCore" Version="10.3.4" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\6GAG.Core\6GAG.Core.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>
我该如何解决这个问题?
【问题讨论】:
-
如果是.net core项目,一定要有Program.cs中的Main函数。如果没有 Main 函数,它将不会运行。
-
@A.Creupelandt Web 应用程序项目也有一个 Program.cs 和一个 Main,它构建了 Web 主机并运行它。所有 .NET Core 应用程序都作为控制台应用程序启动。在具有顶级语句的 .NET 6 中,整个
Program.cs文件本质上是Main方法。您的项目是否以 .NET 6 为目标?csproj文件的内容是什么? -
这是一个 aspnet 核心项目。当我在本地构建它时它会构建
-
@PanagiotisKanavos 我添加了 .csproj 文件的内容
标签: asp.net-core dockerfile asp.net-core-webapi .net-6.0