我正在尝试在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
这是管道的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://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
我尝试使用XamarinAndroid @ 1构建任务而不是构建整个解决方案,但是它具有完全相同的构建错误。
我从一个完全相同的问题的同事那里找到了一个很好的解决方案,它是从VSBuild任务触发Restore目标,而不是执行NuGet restore / dotnet restore,这里是YAML:
- task: VSBuild@1
displayName: 'Restore Packages'
inputs:
solution: '**/$(solutionName)'
configuration: '$(buildConfiguration)'
vsVersion: '16.0'
msbuildArgs: '/t:Restore'
这非常适合构建整个解决方案。