获取“程序不包含适用于入口点的静态'Main'方法".使用docker构建时,为什么? [英] Getting "Program does not contain a static 'Main' method suitable for an entry point" when building using docker, why?

查看:54
本文介绍了获取“程序不包含适用于入口点的静态'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.com/dotnet/core/aspnet:3.1-buster-slim-arm64v8 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/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构建时,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆