Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a YAML build pipeline in azure devops for xamarin projects with referenced dot net projects

I recently moved my sources to azure devOps to use cd/ci and all the other cool stuff. Now i created my first build pipeline to build the android part of my Xamarin project. But I end up getting an error message, that a resource of a referenced project could not be found and i shall do a package restore and try again. Now, since i have azure hosted build agents and not self hosted, i have no ways of setting the agent up properly before doing the build. But i guess there should be some way to properly configure the build pipeline to do all the necessary stuff. Its just that i have no clue what i should add to my yaml file in order to fix this stuff.

This is the error message i got:

##[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.

The problem is, that this file should be generated by compiling a referenced project and is not part of a nuget package.

Here is my build pipeline as far as i figured it out by myself.

# Xamarin.Android
# Build a Xamarin.Android project.
# Add steps that test, sign, and distribute an app, save build artifacts, and more:
# https://learn.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)'

The build always breaks on step XamarinAndroid

I hope you can help me. The solution must be out there somewhere, i just cannot see it right now. Thx in Advance. Mav

like image 976
Maverick1st Avatar asked Sep 24 '19 11:09

Maverick1st


1 Answers

[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.

According to this error message, the project is .NetCore and its SDK used is 2.2.105. For the file "....\obj\project.assets.json", whether the project.assets.json exists is determined by package restore step. Now, it prompt this could not be found, it means the package restore does not restore this file successfully.

As I mentioned previously, it is a .NetCore project. So you should use dotnet restore instead of nuget restore. For .NetCore project, the obj folder restored by nuget restore does not contain project.assets.json in it.

enter image description here

So, to solve the issue you meet, you should replace the task Nuget restore as dotnet restore: dotnet.

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: '**/*.csproj'
    vstsFeed: 'e157d03d-******-fc06f9e13177'
like image 192
Mengdi Liang Avatar answered Nov 11 '22 01:11

Mengdi Liang