错误消息“程序不包含适用于入口点的静态"Main"方法".

编程入门 行业动态 更新时间:2024-10-27 17:15:28
本文介绍了错误消息“程序不包含适用于入口点的静态"Main"方法".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个ASP.NET CORE应用程序,其中包含一些项目以及以下Dockerfile:

I have an ASP.NET CORE app with a few projects inside and the following Dockerfile:

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base WORKDIR /app EXPOSE 80 FROM microsoft/dotnet:2.2-sdk AS build WORKDIR /src COPY src/Mbv.Vans.Core/Mbv.Vans.Core.csproj Mbv.Vans.Core/ COPY src/Mbv.Vans.Common/Mbv.Vans.Common.csproj Mbv.Vans.Common/ COPY src/Mbv.Vans.Api/Mbv.Vans.Api.csproj Mbv.Vans.Api/ RUN dotnet restore Mbv.Vans.Api/Mbv.Vans.Api.csproj COPY . . FROM build AS publish RUN dotnet publish Mbv.Vans.Api/Mbv.Vans.Api.csproj --no-restore -c Release -o /app FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "Mbv.Vans.Api.dll"]

在线 RUN dotnet上发布Mbv.Vans.Api/Mbv.Vans.Api.csproj --no-restore -c Release -o/app 尝试构建项目时失败出现错误:

On line RUN dotnet publish Mbv.Vans.Api/Mbv.Vans.Api.csproj --no-restore -c Release -o /app When it tries to build the project, it fails with error:

程序不包含适用于入口点的静态'Main'方法"

"Program does not contain a static 'Main' method suitable for an entry point"

这是我的.csproj文件:

Here is my .csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp2.2</TargetFramework> <GenerateDocumentationFile>true</GenerateDocumentationFile> <NoWarn>1591</NoWarn> <GenerateProgramFile>false</GenerateProgramFile> </PropertyGroup>

我搜索了很多有关此问题的问题,并将其分为以下解决方案:

I searched a lot of questions regarding this issue and divide it into the following resolutions:

  • COPY..无法解决此问题
  • 我只有一个 static void main
  • < GenereteProgramFile>错误没有帮助.
  • COPY . . is not fixing this issue
  • I have only one static void main
  • <GenereteProgramFile> false doesn't help.
  • 有人可以帮我解决这个严重的问题吗?

    Could someone can help me to beat this awfull issue?

    推荐答案

    因此,我遇到了同样的问题,并使我发疯.这里的解决方案是跳过构建并直接进行发布.

    So, I ran across this same issue and drove me insane. The solution here is to skip the build and go right to a publish.

    通过查看以下特定示例为我提供了帮助: github/dotnet/dotnet-docker/blob/master/samples/aspnetapp/Dockerfile.alpine-x64

    I was helped by looking at this particular sample: github/dotnet/dotnet-docker/blob/master/samples/aspnetapp/Dockerfile.alpine-x64

    如您所见,没有构建发生.有一个还原,然后发布.为什么不建房?我不知道.我正在调查,但我很高兴至少对我有用.让我知道怎么回事.

    As you can see in there, there is no build occurring. There is a restore, and then a publish. Why no build? I don't know. I'm investigating, but I'm happy it worked for me at least. Let me know how it goes.

    已编辑以获取其他信息:

    Edited for additional info:

    这是原始的无法正常工作的Dockerfile:

    Here is the original non-working Dockerfile:

    FROM microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-1809 AS base WORKDIR /app EXPOSE 80 EXPOSE 443 FROM microsoft/dotnet:2.2-sdk-nanoserver-1809 AS build WORKDIR /src COPY ["mercurynorth_netcore/mercurynorth_netcore.csproj", "mercurynorth_netcore/"] RUN dotnet restore "mercurynorth_netcore/mercurynorth_netcore.csproj" COPY . . WORKDIR "/src/mercurynorth_netcore" RUN dotnet build "mercurynorth_netcore.csproj" -c Release -o /app FROM build AS publish RUN dotnet publish "mercurynorth_netcore.csproj" -c Release -o /app FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "mercurynorth_netcore.dll"]

    ...这里是新使用的Dockerfile:

    ...and here the the newly working Dockerfile:

    FROM mcr.microsoft/dotnet/core/sdk:2.2-alpine AS build WORKDIR /app # Lets do a restore of the NuGet packages, and then restore the app in a container. COPY mercurynorth_netcore.csproj ./ RUN dotnet restore "mercurynorth_netcore.csproj" COPY . . RUN dotnet publish "mercurynorth_netcore.csproj" -c Release -o /app FROM mcr.microsoft/dotnet/core/aspnet:2.2 AS final WORKDIR /app EXPOSE 80 EXPOSE 443 COPY --from=build /app . ENTRYPOINT ["dotnet", "mercurynorth_netcore.dll"]

    如您所见,我通常所做的是删除该行:

    As you can see, what I generally did was remove the line:

    RUN dotnet build "mercurynorth_netcore.csproj" -c Release -o /app

    ...以及进行一些清理.

    ...as well as do some clean-up.

    一般来说,在我的开发机上运行build命令可以正常工作,但是作为构建容器的一部分,它将失败.

    The general take-away is that running the build command on my dev machine(s) will work fine, but as part of building the container, it will fail.

    更多推荐

    错误消息“程序不包含适用于入口点的静态"Main"方法".

    本文发布于:2023-11-15 12:36:51,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1594505.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:适用于   静态   不包含   入口   错误

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!