无法在Azure Pipelines中构建Xamarin Android项目

7

我正在尝试在Azure DevOps中创建一个基本的构建流水线,用于构建包含.NET Core/.NET Standard项目和Xamarin.Android项目的Visual Studio解决方案。该解决方案可以在本地使用VS 2019成功构建,但总是在构建代理上失败,并出现以下构建错误:

Error APT2260: resource style/Theme.AppCompat.Light.Dialog (aka com.companyname.obrien.connect.forms:style/Theme.AppCompat.Light.Dialog) not found.

Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(4,0): Error APT2260: style attribute 'attr/colorAccent (aka com.companyname.obrien.connect.forms:attr/colorAccent)' not found.

Error APT2260: resource style/Theme.AppCompat.Light.DarkActionBar (aka com.companyname.obrien.connect.forms:style/Theme.AppCompat.Light.DarkActionBar) not found.

Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(2,0): Error APT2260: style attribute 'attr/windowNoTitle (aka com.companyname.obrien.connect.forms:attr/windowNoTitle)' not found.

Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(2,0): Error APT2260: style attribute 'attr/windowActionBar (aka com.companyname.obrien.connect.forms:attr/windowActionBar)' not found.

Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(2,0): Error APT2260: style attribute 'attr/colorPrimary (aka com.companyname.obrien.connect.forms:attr/colorPrimary)' not found.

Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(2,0): Error APT2260: style attribute 'attr/colorPrimaryDark (aka com.companyname.obrien.connect.forms:attr/colorPrimaryDark)' not found.

Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(3,0): Error APT2260: style attribute 'attr/colorAccent (aka com.companyname.obrien.connect.forms:attr/colorAccent)' not found.

Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(4,0): Error APT2260: style attribute 'attr/windowActionModeOverlay (aka com.companyname.obrien.connect.forms:attr/windowActionModeOverlay)' not found.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Aapt2.targets(155,3): Error APT2260: resource style/TextAppearance.AppCompat.Button (aka com.companyname.obrien.connect.forms:style/TextAppearance.AppCompat.Button) not foun

这是管道的YAML代码:

trigger:
- develop
- feature/*

pool:
  vmImage: 'windows-2019'

variables:
- group: 'ci-build'

steps:
- task: NuGetToolInstaller@1
  displayName: 'Install NuGet 5.4.0' 
  inputs:
    versionSpec: '5.4.0'

- task: DotNetCoreCLI@2
  displayName: 'Restore .NET Packages'
  inputs:
    command: restore
    projects: '**/OBrien.Connect.Forms*/*.csproj'
    verbosityRestore: minimal

- task: NuGetCommand@2
  displayName: 'Restore Android Packages'
  inputs:
    command: 'restore'
    restoreSolution: '**/OBrien.Connect.Forms.sln'

- task: VSBuild@1
  displayName: 'Build Solution'
  inputs:    
    solution: '**/$(solutionName)' 
    vsVersion: '16.0'
    configuration: '$(buildConfiguration)'

我需要先在解决方案中的项目上使用dotnet restore,这样我才能通过后续的VSBuild任务来构建它们,这个方法是有效的。然而,这不会恢复Xamarin.Android项目所需的任何软件包,因为它基于Mono并被第一个还原所忽略。

这就是为什么我在整个解决方案中添加了第二个NuGet还原,但它从未做过任何事情——没有错误,只有这个输出:

##[section]Starting: Restore Android Packages
==============================================================================
Task         : NuGet
Description  : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
Version      : 2.161.1
Author       : Microsoft Corporation
Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/package/nuget
==============================================================================
SYSTEMVSSCONNECTION exists true
SYSTEMVSSCONNECTION exists true
[command]C:\windows\system32\chcp.com 65001
Active code page: 65001
Detected NuGet version 5.4.0.6315 / 5.4.0+d790b66be476cd901a56bd46ada037162097ee21.d790b66be476cd901a56bd46ada037162097ee21
SYSTEMVSSCONNECTION exists true
Saving NuGet.config to a temporary config file.
[command]C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe sources Add -NonInteractive -Name NuGetOrg -Source https://api.nuget.org/v3/index.json -ConfigFile D:\a\1\Nuget\tempNuGet_552.config
Package source with Name: NuGetOrg added successfully.
##[section]Finishing: Restore Android Packages

我尝试使用XamarinAndroid@1构建任务代替构建整个解决方案,但是它仍然出现完全相同的构建错误。


删除项目中的 binobj 文件夹,然后进行清理和重建。 - Lucas Zhang
1个回答

6

我从一个有着同样问题的同事那里找到了一个好的解决方案,即通过 VSBuild 任务触发 Restore 目标,而不是执行 NuGet restore / dotnet restore。以下是 YAML 配置:

- task: VSBuild@1
  displayName: 'Restore Packages'
  inputs:
    solution: '**/$(solutionName)'
    configuration: '$(buildConfiguration)'
    vsVersion: '16.0'
    msbuildArgs: '/t:Restore'

这适用于构建整个解决方案,非常完美。


尝试将此添加到macOS虚拟机中,但它显示该任务无法在此操作系统上运行。理想情况下,希望能够在同一构建虚拟机上依次构建Android和iOS,这需要macOS :( - MPavlak
1
它在Windows虚拟机上可以工作。我想我得创建一个新的任务来构建iOS,使用macOS镜像。这个救了我!不确定为什么它已经破了这么久。我想是在七月份更新Xamarin.Forms包之后发生的。 - MPavlak

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接