How can I create a YAML pipeline in Azure Devops for a Xamarin Forms Android library project that generates a nuget package

Viewed 240

I have a Xamarin Forms Android project configured to generate a nuget package when it is compiled from Visual Studio (will be used as a library), but in the Azure pipeline configuration something is not working in the "Generate Nuget package" task.

This is the configuration in the YAML file:

pool:
  vmimage: 'windows-2019'

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

steps:
- task: DotNetCoreCLI@2
  displayName: Restore Nuget packages
  inputs:
    command: 'restore'
    projects: '**/*.Droid.csproj'
    feedsToUse: 'select'
    vstsFeed: '426fe2cd-0983-468f-b5bd-8073930ec94c'

- task: XamarinAndroid@1
  displayName: Build project
  inputs:
    projectFile: '**/*.Droid.csproj'
    outputDirectory: '$(outputDirectory)'
    createAppPackage: true
    configuration: '$(buildConfiguration)'
    msbuildVersionOption: '16.0'

- task: DotNetCoreCLI@2
  displayName: Generate Nuget package
  inputs:
    command: 'pack'
    packagesToPack: '**/*.Droid.csproj'
    versioningScheme: 'off'

- task: DotNetCoreCLI@2
  displayName: Publish Nuget
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: '426fe2cd-0983-468f-b5bd-8073930ec94c'

And this is the error that shows when I run the pipeline:

D:\a\1\s....Droid.csproj(183,5): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\5.0.401\Xamarin\Android\Xamarin.Android.CSharp.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\5.0.401\Xamarin\Android\Xamarin.Android.CSharp.targets" is correct, and that the file exists on disk.

Other pipelines that I have configured work fine and are generating the nuget packages, but they are just Xamarin Forms projects, they don't include Xamarin.Android references.

A YAML example of these projects:

pool:
  vmimage: 'windows-2019'

steps:
- task: DotNetCoreCLI@2
  displayName: Restore Nuget packages
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'select'
    vstsFeed: '426fe2cd-0983-468f-b5bd-8073930ec94c'

- task: DotNetCoreCLI@2
  displayName: Build project
  inputs:
    command: 'build'
    projects: '**/*.csproj'

- task: DotNetCoreCLI@2
  displayName: Generate Nuget package
  inputs:
    command: 'pack'
    packagesToPack: '**/*.csproj'
    versioningScheme: 'off'
    
- task: DotNetCoreCLI@2
  displayName: Publish Nuget
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: '426fe2cd-0983-468f-b5bd-8073930ec94c'
0 Answers
Related