Dotnet在Docker中的Linux错误上发布(Azure DevOps构建) [英] Dotnet publish on linux error in docker (Azure DevOps build)

查看:151
本文介绍了Dotnet在Docker中的Linux错误上发布(Azure DevOps构建)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Azure DevOps中具有自托管的Linux构建代理.我尝试构建并推送docker任务,但出现了这样的错误(本地dotnet构建有效):

I have self-hosted linux build agent in Azure DevOps. I try to build&push docker task and i have an error like this(locally dotnet build worked):

The specified task executable "node" could not be run. System.ComponentModel.Win32Exception (2): No such file or directory [/src/Cillian.csproj]

我的日志:

...
Step 11/26 : RUN dotnet build -c Release -o /app
 ---> Running in 9233fd642015
Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 1.51 sec for /src/Cillian.csproj.
/root/.nuget/packages/microsoft.typescript.msbuild/3.0.0/tools/Microsoft.TypeScript.targets(293,5): error MSB6003: The specified task executable "node" could not be run. System.ComponentModel.Win32Exception (2): No such file or directory [/src/Cillian.csproj]
...

管道: AzureDevOpsImg

我的Dockerfile:

My Dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src

COPY *.csproj ./
RUN dotnet restore
COPY . .
WORKDIR /src
RUN dotnet build -c Release -o /app

FROM build AS publish

RUN dotnet publish -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Cillian.dll"]

推荐答案

没有这样的文件或目录

No such file or directory

仅关注此错误消息,dotnet build找不到csproj文件以继续构建.即使可以在本地成功构建,这也是Azure devops中最容易发生的错误.

Just focus on this error message, dotnet build could not find the csproj file to continue the build. This is the mostly prone error in Azure devops even if it can be built successfully in local.

那是因为docker在本地(例如VS)的Repos/solution级别运行. 但是,对于Azure devops CI,它将在项目级别的dockerfile所在的目录中运行docker.

That is because the docker runs at the Repos/solution level locally(e.g. VS). BUT, for Azure devops CI, it running the docker in the directory where the dockerfile lives, which is at project level.

简而言之就是relative path,它可以成功地在本地使用来找到csproj,而在Azure devops中根本不可用.因为工作目录已更改.

The nutshell is the relative path which can succeed to used in the local to find csproj, not avilable in the Azure devops at all. Because the working directory has changed.

请在Docker 2.*自变量Build context中指定$(Build.Repository.LocalPath).

对于 YAML :

- task: Docker@2
  displayName: build
  inputs: 
    containerRegistry: DockerHub
    repository: xxx/xxx
    Dockerfile: Docker/TestWebApi/Dockerfile
    buildContext: '$(Build.Repository.LocalPath)' # Specify the context
    tags: latest

这篇关于Dotnet在Docker中的Linux错误上发布(Azure DevOps构建)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆