如何在具有参考点网项目的xamarin项目的azure devops中创建YAML构建管道

问题描述 投票:6回答:2

我最近将我的资源移到了天蓝色的devOps上,以使用cd / ci和所有其他不错的东西。现在,我创建了我的第一个构建管道来构建Xamarin项目的android部分。但是我最终收到一条错误消息,找不到参考项目的资源,我将还原软件包并重试。现在,由于我拥有azure托管的构建代理而不是自托管的,因此我无法在进行构建之前正确设置代理。但是我想应该有一些方法可以正确地配置构建管道来完成所有必要的工作。只是我不知道我应该将什么添加到我的yaml文件中以修复此问题。

这是我收到的错误消息:

##[error]C:\Program Files\dotnet\sdk\2.2.105\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(208,5): Error NETSDK1004: Assets file 'd:\a\1\s\*****\*****\*****\*****\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.

问题是,该文件应通过编译引用的项目来生成,并且不属于nuget包。

据我自己了解,这是我的构建管道。

# Xamarin.Android
# Build a Xamarin.Android project.
# Add steps that test, sign, and distribute an app, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/xamarin

trigger:
- Share/main

pool:
  vmImage: 'VS2017-Win2016'

variables:
  buildConfiguration: 'Debug'
  outputDirectory: '$(build.binariesDirectory)/$(buildConfiguration)'

steps:
- task: NuGetToolInstaller@1
  inputs:
    versionSpec: 5.1.0

- task: NuGetCommand@2
  displayName: 'Restore NuGet Packages'
  inputs:
    command: restore
    restoreSolution: '**/*.sln'    

- task: XamarinAndroid@1
  inputs:    
    projectFile: 'Mobile4/Droid/Mobile4.Droid.csproj'
    outputDirectory: '$(outputDirectory)'
    configuration: '$(buildConfiguration)'

- task: AndroidSigning@3
  inputs: 
    apksign: false
    zipalign: false
    apkFiles: '$(outputDirectory)/*.apk'

- task: PublishBuildArtifacts@1
  inputs:
      pathtoPublish: '$(outputDirectory)'

构建总是在步骤XamarinAndroid上中断

希望您能帮助我。解决方案必须在某个地方,我现在看不到它。事先感谢。Mav

azure xamarin xamarin.android azure-devops azure-pipelines
2个回答
1
投票

[错误] C:\ Program Files \ dotnet \ sdk \ 2.2.105 \ Sdks \ Microsoft.NET.Sdk \ targets \ Microsoft.PackageDependencyResolution.targets(208,5):错误NETSDK1004:资产文件找不到'd:\ a \ 1 \ s ******************** \ obj \ project.assets.json'。运行NuGet软件包还原以生成此文件。

根据此错误消息,项目为.NetCore,使用的SDK为2.2.105。对于文件“ .... \ obj \ project.assets.json”,是否通过包还原步骤determined project.assets.json是否存在。现在,它提示找不到此提示,这意味着软件包还原无法成功还原此文件。

正如我之前提到的,这是一个.NetCore项目。因此,您应该使用dotnet restore而不是nuget restore。对于。NetCore项​​目,由obj还原的nuget restore文件夹中不包含project.assets.json

enter image description here

因此,要解决您遇到的问题,应将任务Nuget restore替换为dotnet restoredotnet

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: '**/*.csproj'
    vstsFeed: 'e157d03d-******-fc06f9e13177'

0
投票

我有一个

# https://docs.microsoft.com/vsts/pipelines/languages/xamarin

variables:
- group: debugKeystore

jobs:
- job: Android
  pool:
    vmImage: 'vs2017-win2016'
  variables:
    buildConfiguration: 'Release'
    outputDirectory: '$(build.binariesDirectory)/$(buildConfiguration)'
  steps:
  - task: NuGetToolInstaller@0
  - task: NuGetCommand@2
    inputs:
      restoreSolution: '**/*.sln'
  - task: XamarinAndroid@1
    inputs:
      projectFile: '**/MyProject.Android.csproj'
      outputDirectory: '$(outputDirectory)'
      configuration: '$(buildConfiguration)'
  - task: AndroidSigning@3
    inputs:
      apkFiles: '**/*.apk' 
      apksign: true
      apksignerKeystoreFile: 'debug.keystore'
      apksignerKeystorePassword: '$(debugKeystorePassword)'
      apksignerKeystoreAlias: 'androiddebugkey'
      apksignerKeyPassword: '$(debugKeystoreKeyPassword)'
  - task: CopyFiles@2
    inputs:
      contents: '**/*.apk'
      targetFolder: '$(build.artifactStagingDirectory)'
  - task: PublishBuildArtifacts@1

- job: iOS
  pool:
    vmImage: 'macOS-latest'
  variables:
    buildConfiguration: 'Release'
  steps:
# https://github.com/microsoft/appcenter/issues/847#issuecomment-521892024
# - script: xcrun simctl erase all
  - task: NuGetToolInstaller@0
  - task: NuGetCommand@2
    inputs:
      restoreSolution: '**/*.sln'
  - task: XamariniOS@2
    inputs:
      solutionFile: '**/MyProject.iOS.csproj'
      configuration: '$(buildConfiguration)'
      buildForSimulator: true
      packageApp: false
  - task: CopyFiles@2
    inputs:
      contents: '**/*.ipa'
      targetFolder: '$(build.artifactStagingDirectory)'
  - task: PublishBuildArtifacts@1

我希望它会有所帮助。顺便说一句,我使用变量来存储我的钥匙串($(debugKeystorePassword)$(debugKeystoreKeyPassword))的密码。

© www.soinside.com 2019 - 2024. All rights reserved.