我有一个ASP.NET CORE应用程序,其中包含一些项目以及以下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 publish Mbv.Vans.Api/Mbv.Vans.Api.csproj --no-restore -c Release -o /app
上尝试构建项目时,它失败并显示错误:
“程序不包含适用于入口点的静态'Main'方法”
这是我的.csproj文件:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1591</NoWarn>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
我搜索了很多有关此问题的问题,并将其分为以下解决方案:
COPY . .
无法解决此问题static void main
<GenereteProgramFile> false
没有帮助。有人可以帮我解决这个可怕的问题吗?
答案 0 :(得分:0)
因此,我遇到了同样的问题,并使我发疯。此处的解决方案是跳过构建并直接进行发布。
通过查看以下特定示例对我有所帮助:https://github.com/dotnet/dotnet-docker/blob/master/samples/aspnetapp/Dockerfile.alpine-x64
如您所见,没有构建发生。有一个还原,然后发布。为什么没有构建?我不知道。我正在调查,但我很高兴至少对我有用。让我知道怎么回事。
编辑以获取其他信息:
这是原始的无法正常工作的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:
FROM mcr.microsoft.com/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.com/dotnet/core/aspnet:2.2 AS final
WORKDIR /app
EXPOSE 80
EXPOSE 443
COPY --from=build /app .
ENTRYPOINT ["dotnet", "mercurynorth_netcore.dll"]
如您所见,我通常所做的是删除该行:
RUN dotnet build "mercurynorth_netcore.csproj" -c Release -o /app
...以及进行一些清理。
普遍的看法是,在我的开发机上运行build命令可以正常工作,但是作为构建容器的一部分,它将失败。