如何在我的dockerfile上修复“ MSBUILD:错误MSB1011”?

时间:2019-08-12 19:17:17

标签: c# .net docker msbuild dockerfile

我正在按照example设置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

非常感谢您的回答。

1 个答案:

答案 0 :(得分:1)

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

import { Anchor } from "red-components-with-rollup/Anchor";

RUN msbuild /p:Configuration=Release mySolution.sln

这两种方法都应该有助于您逐步完成构建,或者至少可以解决您可能面临的下一个问题。