在Azure DevOps管道中,我正在构建一个包含多个MVC和API项目的c#解决方案。这些项目都支持Docker (Linux),解决方案中还有一个Docker Compose项目。我正在运行Linux容器。该解决方案可以在Visual Studio 2019中本地构建。在Azure DevOps中构建失败,出现以下错误:
DockerComposeProjectBuild:
docker-compose -f "D:a1ssrcdocker-compose.yml" -p dockercompose11375654433676829892 --no-ansi build
Building my-app
Step 1/15 : FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
5.0-buster-slim: Pulling from dotnet/aspnet
Service 'my-app' failed to build : no matching manifest for windows/amd64 10.0.17763 in the manifest list entries
##[error]C:Program Files (x86)Microsoft Visual Studio2019EnterpriseMSBuildSdksMicrosoft.Docker.SdkbuildMicrosoft.VisualStudio.Docker.Compose.targets(491,5): Error : Your Docker server host is configured for 'Windows', however the docker-compose project targets 'Linux'.
在本地,解决方案构建正常,Docker容器运行良好。我的构建管道配置为使用Windows:
pool:
vmImage: 'windows-latest'
当我切换到ubuntu-latest时,构建步骤立即失败:
2021-02-19T09:21:06.4937649Z ##[section]Starting: Build
2021-02-19T09:21:06.4946601Z ==============================================================================
2021-02-19T09:21:06.4947180Z Task : Visual Studio build
2021-02-19T09:21:06.4947617Z Description : Build with MSBuild and set the Visual Studio version property
2021-02-19T09:21:06.4949185Z Version : 1.166.2
2021-02-19T09:21:06.4949536Z Author : Microsoft Corporation
2021-02-19T09:21:06.4950010Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/visual-studio-build
2021-02-19T09:21:06.4950534Z ==============================================================================
2021-02-19T09:21:06.5069612Z ##[error]The current operating system is not capable of running this task. That typically means the task was written for Windows only. For example, written for Windows Desktop PowerShell.
2021-02-19T09:21:06.5083222Z ##[section]Finishing: Build
我已经尝试在解决方案属性中禁用Docker Compose项目的构建,但这似乎没有什么不同。
我如何改变管道来解决这个问题?如果Docker Compose项目在构建过程中被管道跳过也没关系。
您正在使用Azure pipeline中的Windows构建机:
pool:
vmImage: 'windows-latest'
你要求Windows机器构建一个Linux容器:
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim
这个容器映像不能在Windows上工作,因为错误提示:
no matching manifest for windows/amd64
如果您想使用Linux容器,请使用不同的池:
pool:
vmImage: 'ubuntu-latest'
尝试从visual studio中卸载docker项目并编辑该项目并将值设置为"Windows";DockerTargetOS" .
<DockerTargetOS>Windows</DockerTargetOS>