尝试使用 .Net Core 3.0 SDK(预览版 5)在 DevOps 管道中构建时抛出异常“错误 MSB3024:无法复制文件...”

Tin*_*nus 5 core c#-3.0 docker kubernetes azure-devops

我正在尝试.Net Core 3.0 (preview)在 DevOps 构建管道中构建一个项目。

my 中的步骤一直azure-pipelines.yml执行到 " docker build" 步骤,成功启动了构建过程。Docker 文件被读取并执行到“dotnet build”步骤,之后抛出以下错误。

错误 MSB3024:无法将文件“/src/obj/Release/netcoreapp3.0/”复制到目标文件“/app/”,因为目标是文件夹而不是文件。要将源文件复制到文件夹中,请考虑使用 DestinationFolder 参数而不是 DestinationFiles。[/src/.csproj]

我试图通过执行 dotnet build ".csproj" -c Release -o /app 在本地构建然后构建成功,出现 0 个错误和 0 个警告。这可能与 DevOps 中的 SDK 问题有关吗?

任何建议将不胜感激。

来自我的 Docker 文件的构建命令。

RUN dotnet build "<project>.csproj" -c Release -o /app
Run Code Online (Sandbox Code Playgroud)


--- {OMITED}
---1ff83de4bdba
Step 5/16 : WORKDIR /src
---Running in 972629766fad
Removing intermediate container 972629766fad
---1325ecd8e7c3
Step 6/16 : COPY ["<projectname>.csproj", "<projectname>/"]
---a4ba463683dc
Step 7/16 : RUN dotnet restore "<projectname>/<projectname>.csproj"
---Running in 82bb9095d412
Restore completed in 14.08 sec for /src/<projectname>/<projectname>.csproj.
Removing intermediate container 82bb9095d412
---7b0cc236782e
Step 8/16 : COPY . .
---884bb695bfb3
Step 9/16 : WORKDIR /src
---Running in 817b001e2060
Removing intermediate container 817b001e2060
---40b8690ecb63
Step 10/16 : RUN dotnet build "<projectname>.csproj" -c Release -o /app
---Running in 48d79b81c3cb
Microsoft (R) Build Engine version 16.0.462+g62fb89029d for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

Restore completed in 531.02 ms for /src/<projectname>.csproj.
/usr/share/dotnet/sdk/3.0.100-preview5-011568/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(157,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview [/src/<projectname>.csproj]
/usr/share/dotnet/sdk/3.0.100-preview5-011568/Microsoft.Common.CurrentVersion.targets(4560,5): error MSB3024: Could not copy the file "/src/obj/Release/netcoreapp3.0/<projectname>" to the destination file "/app/<projectname>", because the destination is a folder instead of a file. To copy the source file into a folder, consider using the DestinationFolder parameter instead of DestinationFiles. [/src/<projectname>.csproj]

Build FAILED.

/usr/share/dotnet/sdk/3.0.100-preview5-011568/Microsoft.Common.CurrentVersion.targets(4560,5): **error MSB3024: Could not copy the file "/src/obj/Release/netcoreapp3.0/<projectname>" to the destination file "/app/<projectname>", because the destination is a folder instead of a file. To copy the source file into a folder, consider using the DestinationFolder parameter instead of DestinationFiles. **[/src/<projectname>.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:11.43
The command '/bin/sh -c dotnet build "<projectname>.csproj" -c Release -o /app' returned a non-zero code: 1
##[error]Bash exited with code '1'.
##[section]Finishing: docker build
Run Code Online (Sandbox Code Playgroud)

小智 5

就我而言,我必须将项目文件夹重命名为与 dockerfile 中的项目本身不同:

FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
WORKDIR /src
COPY ["<project-name>.csproj", "<project-name>_build/"]
RUN dotnet restore "<project-name>_build/<project-name>.csproj"
Run Code Online (Sandbox Code Playgroud)


小智 5

在我的情况下,我的项目的程序集名称与项目名称相同,也与该项目的目录名称相同。一旦我将项目属性中的程序集名称更改为其他名称,此错误就消失了。


Tin*_*nus 1

我假设这是 .Net Core 3.0 Preview5 SDK 的问题。我已经在 .Net Core 2.2 中创建了该项目,并且构建成功。