1

我正在按照此示例设置 dockerfile 。我被困在下面的命令中。

我的项目最初不包含 csproj 文件。

安慰

Sending build context to Docker daemon  101.6MB
Step 1/10 : FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS build
 ---> 161680d5c6b2
Step 2/10 : WORKDIR /app
 ---> Using cache
 ---> c72d80e3abed
Step 3/10 : COPY *.sln .
 ---> Using cache
 ---> 06bbfc478b4c
Step 4/10 : COPY *.config ./
 ---> Using cache
 ---> f2ebd7396f5a
Step 5/10 : RUN nuget restore
 ---> Using cache
 ---> f3e33c0d2590
Step 6/10 : COPY . ./
 ---> fc8fe6acd4a3
Step 7/10 : RUN msbuild /p:Configuration=Release
 ---> Running in fe213a4b69d5

Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

MSBUILD : error MSB1011: Specify which project or solution file to use because this folder contains more than one project or solution file.
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; msbuild /p:Configuration=Release' returned a non-zero code: 1

我通过构建解决方案并使用它运行平稳的 IIS express 在本地运行它,但我的 dockerfile 不是。下面是我的 dockerfile,其中包含一些说明。

Dockerfile

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.sln .
# COPY aspnetapp/*.csproj ./aspnetapp/
COPY *.config ./
RUN nuget restore

# copy everything else and build app
COPY . ./
# WORKDIR /app
RUN msbuild /p:Configuration=Release


FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8 AS runtime
WORKDIR /inetpub/wwwroot
COPY --from=build /app ./

项目结构

/aspnetapp
├── *.aspx
├── *.aspx.cs
├── App_Code
├── App_Data
├── Documents
├── *.master
├── *.master.cs
├── Scripts
├── Styles
├── Templates
├── *.sln
├── assetinfo.json
├── bin
├── dockerfile
├── images
├── js
├── media
├── packages
├── package.config
├── web.config
└── *.publishproj

非常感谢您的回答。

4

1 回答 1

0

您有多个项目和/或解决方案可能有资格在您所在的工作目录中构建。在这种情况下,您可以直接在 dockerfile 中提供要构建的解决方案的名称。

RUN msbuild /p:Configuration=Release mySolution.sln

或者

RUN msbuild /p:Configuration=Release myProject.csproj

这些中的任何一个都应该可以帮助您完成构建,或者至少可以帮助您解决可能面临的下一个问题。

于 2019-08-12T19:22:50.700 回答