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

Sam*_*Sam 6 xamarin.android nuget xamarin xamarin.forms azure-pipelines

我正在尝试在 Azure DevOps 中创建一个基本的构建管道,它构建了一个 Visual Studio 解决方案,其中包括 .NET Core / .NET Standard 项目和 Xamarin.Android 项目。该解决方案在 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
Run Code Online (Sandbox Code Playgroud)

这是管道的 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)'
Run Code Online (Sandbox Code Playgroud)

我需要先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://docs.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
Run Code Online (Sandbox Code Playgroud)

我尝试使用 XamarinAndroid@1 构建任务而不是构建整个解决方案,但它具有完全相同的构建错误。

Sam*_*Sam 6

我从一位遇到完全相同问题的同事那里找到了一个很好的解决方案,即从 VSBuild 任务触发 Restore 目标,而不是执行 NuGet 恢复/dotnet 恢复,这是 YAML:

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

这非常适合构建整个解决方案。