gpt4 book ai didi

c# - Docker 在 VS 中运行,但在发布到 AWS 时出错?错误 CS5001 : Program does not contain a static 'Main' method suitable for an entry point

转载 作者:IT老高 更新时间:2023-10-28 21:42:08 25 4
gpt4 key购买 nike

我为 Visual Studio 2017 (V15.7.3) 安装了 AWS 工具包,并创建了一个新的空 Asp.Net core 2.1 项目,该项目具有 API 模板和 Linux docker 支持。我可以在 Visual Studio 中运行它。

加载项目后的 Visual Studio Docker 输出

========== Preparing Containers ==========Getting Docker containers ready...docker-compose  -f "C:\work\Strats\docker-compose.yml" -f "C:\work\Strats\docker-compose.override.yml" -f "C:\work\Strats\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose607729401690719332 --no-ansi configThe DOCKER_REGISTRY variable is not set. Defaulting to a blank string.services:  processfiles:    build:      context: C:\work\Strats      dockerfile: ProcessFiles/Dockerfile      target: base    entrypoint: tail -f /dev/null    environment:      ASPNETCORE_ENVIRONMENT: Development      ASPNETCORE_HTTPS_PORT: '44347'      ASPNETCORE_URLS: https://+:443;http://+:80      DOTNET_USE_POLLING_FILE_WATCHER: '1'      NUGET_FALLBACK_PACKAGES: /root/.nuget/fallbackpackages    image: processfiles:dev    labels:      com.microsoft.visualstudio.debuggee.arguments: ' --additionalProbingPath /root/.nuget/packages        --additionalProbingPath /root/.nuget/fallbackpackages  bin/Debug/netcoreapp2.1/ProcessFiles.dll'      com.microsoft.visualstudio.debuggee.killprogram: /bin/bash -c "if PID=$$(pidof        -x dotnet); then kill $$PID; fi"      com.microsoft.visualstudio.debuggee.program: dotnet      com.microsoft.visualstudio.debuggee.workingdirectory: /app    ports:    - published: 49971      target: 80    - published: 44347      target: 443    volumes:    - C:\work\Strats\ProcessFiles:/app:rw    - C:\Users\...\vsdbg\vs2017u5:/remote_debugger:ro    - C:\Users\...\AppData\Roaming\ASP.NET\Https:/root/.aspnet/https:ro    - C:\Users\...\AppData\Roaming\Microsoft\UserSecrets:/root/.microsoft/usersecrets:ro    - C:\Program Files\dotnet\sdk\NuGetFallbackFolder:/root/.nuget/fallbackpackages:ro    - C:\Users\...\.nuget\packages:/root/.nuget/packages:roversion: '3.4'docker ps --filter "status=running" --filter "name=dockercompose607729401690719332_processfiles_" --format {{.ID}} -n 1docker-compose  -f "C:\work\Strats\docker-compose.yml" -f "C:\work\Strats\docker-compose.override.yml" -f "C:\work\Strats\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose607729401690719332 --no-ansi build The DOCKER_REGISTRY variable is not set. Defaulting to a blank string.Building processfilesStep 1/4 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base ---> 04aae08f15c5Step 2/4 : WORKDIR /app ---> Using cache ---> 135955e04284Step 3/4 : EXPOSE 49971 ---> Using cache ---> 2e1bb95e0d70Step 4/4 : EXPOSE 44347 ---> Using cache ---> 89dc3708552dSuccessfully built 89dc3708552dSuccessfully tagged processfiles:devdocker-compose  -f "C:\work\Strats\docker-compose.yml" -f "C:\work\Strats\docker-compose.override.yml" -f "C:\work\Strats\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose607729401690719332 --no-ansi up -d --no-build --force-recreate --remove-orphansThe DOCKER_REGISTRY variable is not set. Defaulting to a blank string.Creating network "dockercompose607729401690719332_default" with the default driverCreating dockercompose607729401690719332_processfiles_1 ... Creating dockercompose607729401690719332_processfiles_1 ... doneDone!  Docker containers are ready.

Docker output when running in Visual Studio

========== Debugging ==========docker ps --filter "status=running" --filter "name=dockercompose607729401690719332_processfiles_" --format {{.ID}} -n 11cad14cb758cLaunching https://localhost:44347/api/values ...

Visual studio Build output

1>------ Build started: Project: docker-compose, Configuration: Debug Any CPU ------1>docker ps --filter "status=running" --filter "name=dockercompose607729401690719332_processfiles_" --format {{.ID}} -n 11>1cad14cb758c1>docker exec -i 1cad14cb758c /bin/bash -c "if PID=$(pidof -x dotnet); then kill $PID; fi"1>C:\work\Strats\ProcessFiles\ProcessFiles.csproj : warning NU1701: Package 'System.Linq.Queryable 4.0.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project.1>ProcessFiles -> C:\work\Strats\ProcessFiles\bin\Debug\netcoreapp2.1\ProcessFiles.dll1>Done building project "ProcessFiles.csproj".1>docker-compose  -f "C:\work\Strats\docker-compose.yml" -f "C:\work\Strats\docker-compose.override.yml" -f "C:\work\Strats\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose607729401690719332 --no-ansi up -d1>The DOCKER_REGISTRY variable is not set. Defaulting to a blank string.1>dockercompose607729401690719332_processfiles_1 is up-to-date========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

So it runs and shows the default value api sample in browser.

Now I right click the project and click "Publish container to AWS..." after a fix on the Dockerfile (Docker for Windows building added prefix `/var/lib/docker/tmp/` for COPY?). However, it failed with the following messages in AWS message box?

Inspecting Dockerfile to figure how to build project and docker image... Skip building project since it is done as part of DockerfileExecuting docker build... invoking 'docker build', working folder 'C:\work\Strats\ProcessFiles, docker file C:\work\Strats\ProcessFiles\Dockerfile, image name processfiles:latest'... docker build: Sending build context to Docker daemon  1.176MB... docker build: Step 1/17 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base... docker build:  ---> 04aae08f15c5... docker build: Step 2/17 : WORKDIR /app... docker build:  ---> Using cache... docker build:  ---> 135955e04284... docker build: Step 3/17 : EXPOSE 49971... docker build:  ---> Using cache... docker build:  ---> 2e1bb95e0d70... docker build: Step 4/17 : EXPOSE 44347... docker build:  ---> Using cache... docker build:  ---> 89dc3708552d... docker build: Step 5/17 : FROM microsoft/dotnet:2.1-sdk AS build... docker build:  ---> 7c3e298d40ac... docker build: Step 6/17 : WORKDIR /src... docker build:  ---> Using cache... docker build:  ---> 6b6446592420... docker build: Step 7/17 : COPY ProcessFiles.csproj ProcessFiles/... docker build:  ---> 024a84501cff... docker build: Step 8/17 : RUN dotnet restore ProcessFiles/ProcessFiles.csproj... docker build:  ---> Running in 1ef41c99d3bc... docker build:   Restoring packages for /src/ProcessFiles/ProcessFiles.csproj...... docker build:   Generating MSBuild file /src/ProcessFiles/obj/ProcessFiles.csproj.nuget.g.props.... docker build:   Generating MSBuild file /src/ProcessFiles/obj/ProcessFiles.csproj.nuget.g.targets.... docker build:   Restore completed in 770.82 ms for /src/ProcessFiles/ProcessFiles.csproj.... docker build: Removing intermediate container 1ef41c99d3bc... docker build:  ---> 276efaf02bd4... docker build: Step 9/17 : COPY . .... docker build:  ---> 128814476275... docker build: Step 10/17 : WORKDIR /src/ProcessFiles... docker build: Removing intermediate container 004eb873b480... docker build:  ---> 8c1741062d87... docker build: Step 11/17 : RUN dotnet build ProcessFiles.csproj -c Release -o /app... docker build:  ---> Running in fd25517b7941... docker build: Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core... docker build: Copyright (C) Microsoft Corporation. All rights reserved.... docker build:   Restore completed in 55.9 ms for /src/ProcessFiles/ProcessFiles.csproj.... docker build: CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/ProcessFiles/ProcessFiles.csproj]... docker build: Build FAILED.... docker build: CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/ProcessFiles/ProcessFiles.csproj]... docker build:     0 Warning(s)... docker build:     1 Error(s)... docker build: Time Elapsed 00:00:02.56... docker build: The command '/bin/sh -c dotnet build ProcessFiles.csproj -c Release -o /app' returned a non-zero code: 1Error executing "docker build"Attempting to clean up any ELB resources created for the failed deploymentUnknown error publishing container to AWS

Here is the main method created by VS.

namespace ProcessFiles
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}

Dockerfile

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 49971
EXPOSE 44347

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ProcessFiles.csproj ProcessFiles/
RUN dotnet restore ProcessFiles/ProcessFiles.csproj
COPY . .
WORKDIR /src/ProcessFiles
RUN dotnet build ProcessFiles.csproj -c Release -o /app

FROM build AS publish
RUN dotnet publish ProcessFiles.csproj -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "ProcessFiles.dll"]

最佳答案

构建阶段的路径很不稳定。您的项目文件正在复制到子文件夹 /src/ProcessFiles,但源文件正在复制到 /src。在复制之前设置 WORKDIR 应该可以让它们到达正确的位置。

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ProcessFiles.csproj ProcessFiles/
RUN dotnet restore ProcessFiles/ProcessFiles.csproj
WORKDIR /src/ProcessFiles
COPY . .
RUN dotnet build ProcessFiles.csproj -c Release -o /app

关于c# - Docker 在 VS 中运行,但在发布到 AWS 时出错?错误 CS5001 : Program does not contain a static 'Main' method suitable for an entry point,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50863823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com