尝试使用 .Net Core 3.0 SDK 在 DevOps 管道中生成时引发异常"error MSB3024: Could not copy the file..."(预览版5)



我正在尝试在DevOps构建Pipeline中构建.Net Core 3.0 (preview)项目。

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

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

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

任何建议都将不胜感激。

我的docker文件的构建命令。

RUN dotnet build "<project>.csproj" -c Release -o /app


--- {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

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

在我的情况下,我必须将项目文件夹重命名为与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"

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

在dotnet build命令上添加以下参数时,构建在.net core 3.0

中成功

运行dotnet build" .csproj" -c版本 -r linux-musl-x64 -o/app - no-Restore

下面的Dockerfile在DevOps中成功构建

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
WORKDIR /src
COPY ["<project-name>.csproj", "<project-name>/"]
RUN dotnet restore "<project-name>/<project-name>.csproj" -r linux-musl-x64
COPY  . "<project-name>/"
WORKDIR "/src/<project-name>"
RUN dotnet build "<project-name>.csproj" -c Release -r linux-musl-x64 -o /app --no-restore
FROM build AS publish
RUN dotnet publish "<project-name>.csproj" -c Release -r linux-musl-x64 -o /app --no-restore
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "<project-name>.dll"]

相关内容

最新更新