我见过许多类似的问题,但似乎没有一个问题确切地代表了我所面临的问题。创建文件夹结构时,如下所示:
./
./src
./src/test
然后导航到./src/test
并运行dotnet new webapi -lang c#
,这将创建一个工作良好的最小API。我也可以运行dotnet publish -c RELEASE -o out /p:Version=1.0.0
,没有任何问题。
然后,当我尝试在根级创建一个具有以下内容的docker文件时:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG BUILDCONFIG=RELEASE
ARG VERSION=1.0.0
COPY ./src/test/test.csproj ./src/test/
RUN dotnet restore ./src/test/test.csproj
COPY ./src/ ./
WORKDIR ./src/test/
RUN dotnet publish -c $BUILDCONFIG -o out /p:Version=$VERSION
FROM mcr.microsoft.com/dotnet/sdk:6.0
WORKDIR /app
COPY --from=build /src/test/out ./
EXPOSE 5000
ENTRYPOINT ["dotnet", "test.dll"]
我得到以下输出:
=> ERROR [build 6/6] RUN dotnet publish -c RELEASE -o out /p:Version=1.0.0 2.5s
------
> [build 6/6] RUN dotnet publish -c RELEASE -o out /p:Version=1.0.0:
#11 0.511 Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET
#11 0.511 Copyright (C) Microsoft Corporation. All rights reserved.
#11 0.511
#11 0.931 Determining projects to restore...
#11 1.153 All projects are up-to-date for restore.
#11 2.400 CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/test/test.csproj]
我尝试了几种方法,包括将csproj中的OutputType
设置为Exe
,将DockerDefaultTargetOS
设置为win/linux,以及在其他线程中找到的其他一些建议,但最终我总是得到相同的错误。有什么想法可能是错的吗?
发布于 2022-04-20 18:37:32
我在Mac上使用Visual (预览)也有同样的问题。将Dockerfile移动到解决方案根文件夹,然后所有操作都正常。
由于某种原因,Visual将Dockerfile放在\Users\robk\git\Play-With-Containers\Play-With-Containers\Dockerfile
后,右键单击> Add > after支持。(这也是.csproj文件所在的地方)
将Dockerfile拖到一个级别到\Users\robk\git\Play-With-Containers
,然后它就工作了。
https://stackoverflow.com/questions/71669487
复制相似问题