获取“程序不包含适用于入口点的静态'Main'方法".使用docker构建时,为什么?

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

我在使用docker时遇到问题,找不到合适的解决方案.

Im running into an issue using docker and couldn't find a proper solution.

我正在尝试使用dotnet sdk 2.1构建docker映像.

I'm trying to build a docker image using dotnet sdk 2.1.

问题是,当docker尝试运行build语句时,它将失败并且错误输出为

The thing is that when docker tries to run the build statement, it fails and the error output is

CSC:错误CS5001:程序不包含静态的"Main"方法适合进入点

CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point

有趣的是,如果我在本地命令行上执行构建的语句,它会很好地工作.

The funny thing is that if i perform the buildd statement on command line locally, it works fine.

我已经在项目上检查了LanguageVersion标记,它是7.3.

I have already checked my LanguageVersion tag on the project and it is 7.3.

这是我的docker文件

here is my docker file

FROM microsoft/dotnet:2.1-sdk AS builder WORKDIR /src COPY ./nuget ./nuget COPY ./NuGet.Config ./ COPY Services/AadTracking ./ # Copy all the referenced projects COPY ./Services/AadTracking/Company/Company.Service.AadTracking/Company.Service.AadTracking.csproj ./AadTracking/Company/Company.Service.AadTracking/Company.Service.AadTracking.csproj COPY ./Services/AadTracking/Office.Re.Service.AadTracking/Office.Re.Service.AadTracking.csproj ./AadTracking/Office.Re.Service.AadTracking/Office.Re.Service.AadTracking.csproj COPY ./Services/AadTracking/Company/Office.Re.Service.AadTracking.Company/Office.Re.Service.AadTracking.Company.csproj ./AadTracking/Company/Office.Re.Service.AadTracking.Company/Office.Re.Service.AadTracking.Company.csproj COPY ./Services/AadTracking/Office.Re.Service.AadTracking.EventStore/Office.Re.Service.AadTracking.EventStore.csproj ./AadTracking/Office.Re.Service.AadTracking.EventStore/Office.Re.Service.AadTracking.EventStore.csproj # Restore packages RUN dotnet restore "./AadTracking/Company/Company.Service.AadTracking/Company.Service.AadTracking.csproj" RUN dotnet build -c Debug --no-restore "./AadTracking/Company/Company.Service.AadTracking/Company.Service.AadTracking.csproj" # COPY source code #aad tracking COPY ./Services/AadTracking/Company/Company.Service.AadTracking ./AadTracking/Company/Company.Service.AadTracking/ COPY ./Services/AadTracking/Office.Re.Service.AadTracking ./AadTracking/Office.Re.Service.AadTracking/ COPY ./Services/AadTracking/Company/Office.Re.Service.AadTracking.Company ./AadTracking/Company/Office.Re.Service.AadTracking.Company/ COPY ./Services/AadTracking/Office.Re.Service.AadTracking.EventStore ./AadTracking/Office.Re.Service.AadTracking.EventStore/ # Publish RUN dotnet publish "./AadTracking/Company/Company.Service.AadTracking/Company.Service.AadTracking.csproj" -c Debug -o "../../dist" # #Build the app image FROM microsoft/dotnet:2.1-aspnetcore-runtime WORKDIR /app ENV ASPNETCORE_ENVIRONMENT Switch ENV REINSURANCE_INSTANCE Docker-dev COPY --from=builder /dist . ENTRYPOINT ["dotnet", "Company.Service.AadTracking.dll"]

感谢您的帮助!

推荐答案

我知道答案来得有点迟.VS 2019仍然与netcore 3.1存在相同的问题.我偷看了Microsoft提供的示例.原来docker文件位于解决方案的其他位置,并且docker copy命令无法正常工作.

I know this is little bit late to answer. Still VS 2019 has the same issue with netcore 3.1. I took a peek at the examples provided by Microsoft. Turns out the docker file resided in a different place in the solution and docker copy command wasn't working properly.

您必须将docker文件上移一个目录,以便它们与sln文件处于同一级别.它将解决此问题.

You have to move your docker file One directory up, so that they are at the same level as the sln file. It will fix the issue.

或者您还可以更改以下示例docker文件的路径,而无需更改docker文件的位置,恕我直言,最好将docker文件与其他文件保存在一起.

FROM mcr.microsoft/dotnet/core/aspnet:3.1-buster-slim-arm64v8 AS base WORKDIR /app EXPOSE 80 EXPOSE 443 FROM mcr.microsoft/dotnet/core/sdk:3.1-buster AS build WORKDIR /src COPY ["WhatzThat.Web.csproj", "WhatzThat.Web/"] RUN dotnet restore "WhatzThat.Web/WhatzThat.Web.csproj" -r linux-arm64 WORKDIR "/src/WhatzThat.Web" COPY . . RUN dotnet build "WhatzThat.Web.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "WhatzThat.Web.csproj" -c Release -o /app/publish -r linux-arm64 --self-contained false --no-restore FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "WhatzThat.Web.dll"]

更多推荐

获取“程序不包含适用于入口点的静态'Main'方法".使用docker构建时,为什么?

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

发布评论

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

>www.elefans.com

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