Exception “error MSB3024: Could not copy the file…” is thrown when attempting to build in DevOps pipeline using .Net Core 3.0 SDK (preview5)

匆匆过客 提交于 2020-01-24 09:47:10

问题


I am attempting to build a .Net Core 3.0 (preview) project in a DevOps build pipeline.

The steps in my azure-pipelines.yml executes up to the "docker build" step, successfully initiating the build process. The Docker file is read and executed up to the "dotnet build" step after which the following error is thrown.

error MSB3024: Could not copy the file "/src/obj/Release/netcoreapp3.0/" to the destination file "/app/", 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/.csproj]

I have attempted to build locally by executing dotnet build ".csproj" -c Release -o /app The build then succeeds with 0 errors and 0 warnings. Could this be related to an SDK issue in DevOps?

Any advice would be greatly appreciated.

The build command from my Docker file.

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

回答1:


I am assuming this is an issue with the .Net Core 3.0 preview5 SDK. I have created the project in .Net Core 2.2 and it build successfully.




回答2:


in my case i had to rename the project folder to be different than the project itself in 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"



回答3:


When adding the following parameters on the dotnet build command, the build succeeds in .Net Core 3.0

RUN dotnet build ".csproj" -c Release -r linux-musl-x64 -o /app --no-restore

The DockerFile below built successfully in 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"]


来源:https://stackoverflow.com/questions/56293141/exception-error-msb3024-could-not-copy-the-file-is-thrown-when-attempting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!