tdimmig
tdimmig

Reputation: 730

How to build Xamarin.Mac app on Azure pipelines

Azure pipelines has tasks that support building Xamarin apps for iOS and Android. For iOS this includes the optional capability to package a .ipa file that is suitable for upload to the store.

For my project I'm building a macOS app with Xamarin.Mac and looking to be able to automate the build in Azure pipelines, but get stuck at the packaging step. Using an msbuild invocation I can have the .app built and signed in the pipeline just fine.

The next step in the VisualStudio GUI would be clicking "Build->Archive for Publishing", which produces a .xcarchive file (not entirely sure what this is? Just a zip maybe?), then you can click "Sign and Distribute" to go through a wizard that will produce the .pkg file for submission to the store.

This part is what I can't find a way to do in the pipeline. Is there a manual command line way to build the signed .pkg file in lieu of direct support for Xamarin.Mac?

EDIT: I found this article, but adding the "/p:ArchiveOnBuild=true" argument to my msbuild invocation still has not produced an xcarchive file. The docs seem to indicate that it should, so I'm at a loss there.

Upvotes: 4

Views: 412

Answers (1)

EsbenB
EsbenB

Reputation: 3406

Old post but never the less; I have just spent most of a day struggling with the same problem.

I found this excellent blog-post helping a bunch https://witekio.com/blog/xamarin-mac-on-azure-devops/

The idea is basically to build on MacOS and use bash instead of Powershell

I ended up with the following pipeline:

    trigger:
    - master
    
    variables:
      #app data
      outputAppName: '<Name of outputtet app without .app>'
      projectName: '<Name of your project>'
    
      #keys and accounts
      azureSubscription: <Azure subscription for publishing result>
      storageAccountKey: <storage account key>
      storageAccountName: <storage account name>
      storageContainerName: <storage container name>
     
# Working Directory
  workingDirectory: '$(System.DefaultWorkingDirectory)/$(projectName)'
  configuration: 'Release'
  outputArtifactPath: '$(workingDirectory)/$(projectName)/bin/$(configuration)/$(outputAppName).app'
 
  # Agent VM image name
  vmImageName: 'macos-latest'

  

stages:
- stage: Build
  displayName: Build stage

  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
    
      - checkout: self  # self represents the repo where the initial Pipelines YAML file was found
        displayName: Check out 
        clean: true
        #lfs: false  # whether to download Git-LFS files
        submodules: true   # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
        persistCredentials: true  
        path: htpaa_backend_shared_util
        condition: 

      - task: Bash@3
        displayName: 'Change Mono version'
        inputs:
          targetType: 'inline'
          script: |
            SYMLINK=6_4_0
            MONOPREFIX=/Library/Frameworks/Mono.framework/Versions/$SYMLINK
            echo "##vso[task.setvariable variable=DYLD_FALLBACK_LIBRARY_PATH;]$MONOPREFIX/lib:/lib:/usr/lib:$DYLD_LIBRARY_FALLBACK_PATH"
            echo "##vso[task.setvariable variable=PKG_CONFIG_PATH;]$MONOPREFIX/lib/pkgconfig:$MONOPREFIX/share/pkgconfig:$PKG_CONFIG_PATH"
            echo "##vso[task.setvariable variable=PATH;]$MONOPREFIX/bin:$PATH"

      - task: NuGetToolInstaller@1
        displayName: 'Use NuGet'

      - task: NuGetCommand@2
        displayName: 'NuGet restore'
        inputs:
          restoreSolution: '$(workingDirectory)/*.sln'
    
      - task: MSBuild@1
        inputs:
          solution: '$(workingDirectory)/*.sln'
          platform: 'Any CPU'
          configuration: '$(configuration)'
          restoreNugetPackages: true
      - task: ArchiveFiles@2
        inputs:
          rootFolderOrFile: '$(outputArtifactPath)'
          includeRootFolder: true
          archiveType: 'zip'
          archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)_$(projectName).zip'
          replaceExistingArchive: true
          verbose: true
          
      - task: AzureCLI@2
        displayName: 'CLI Copy files to Azure Storage'
        inputs:
            azureSubscription: '$(azureSubscription)'
            scriptType: ps
            scriptLocation: inlineScript
            inlineScript: |
             az storage blob upload --account-name $(storageAccountName) --container-name $(storageContainerName) --name '$(Build.BuildId)_$(projectName).zip' --file '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)_$(projectName).zip'  --account-name $(storageAccountName) --account-key $(storageAccountKey)
      

Upvotes: 0

Related Questions