Build Xamarin apps
This guidance explains how to automatically build Xamarin apps for Android and iOS.
For a working example of how to build a Xamarin app, import (into Azure Repos or TFS) or fork (into GitHub) this repo:
The sample code includes an
azure-pipelines.yml file at the root of the repository. You can use this file to build the app.
Follow all the instructions in Create your first pipeline to create a build pipeline for the sample app.
You can use Azure Pipelines to build your Xamarin apps without needing to set up any infrastructure of your own. Xamarin tools are preinstalled on Microsoft-hosted agents in Azure Pipelines. You can use macOS or Windows agents to run Xamarin.Android builds, and macOS agents to run Xamarin.iOS builds. If you are using a self-hosted agent, you must install Visual Studio Tools for Xamarin for Windows agents or Visual Studio for Mac for macOS agents.
For the exact versions of Xamarin that are preinstalled, refer to Microsoft-hosted agents.
Create a file named azure-pipelines.yml in the root of your repository. Then, add the following snippet to your
azure-pipelines.yml file to select the appropriate agent pool:
# https://docs.microsoft.com/azure/devops/pipelines/ecosystems/xamarin pool: vmImage: 'macOS-10.15' # For Windows, use 'windows-2019'
Build a Xamarin.Android app
To build a Xamarin.Android app, add the following snippet to your
azure-pipelines.yml file. Change values to match your project configuration. See the Xamarin.Android task for more about these options.
variables: buildConfiguration: 'Release' outputDirectory: '$(build.binariesDirectory)/$(buildConfiguration)' steps: - task: NuGetToolInstaller@0 - task: NuGetCommand@2 inputs: restoreSolution: '**/*.sln' - task: XamarinAndroid@1 inputs: projectFile: '**/*Droid*.csproj' outputDirectory: '$(outputDirectory)' configuration: '$(buildConfiguration)'
Sign a Xamarin.Android app
See Sign your mobile Android app during CI for information about signing your app.
See Android guidance for information about:
- Signing and aligning an Android APK
- Testing on the Android Emulator
- Testing on Azure-hosted devices
- Retaining build artifacts with the build record
- Distributing through App Center
- Distributing through Google Play
Build a Xamarin.iOS app
To build a Xamarin.iOS app, add the following snippet to your
azure-pipelines.yml file. Change values to match your project configuration. See the Xamarin.iOS task for more about these options.
variables: buildConfiguration: 'Release' steps: - task: XamariniOS@2 inputs: solutionFile: '**/*iOS.csproj' configuration: '$(buildConfiguration)' packageApp: false buildForSimulator: true
Sign and provision a Xamarin.iOS app - The PackageApp option
To generate a signed and provisioned Xamarin.iOS app .ipa package, set
true and make sure prior to this task you installed the right Apple Provisioning Profile and Apple Certificates that match your App Bundle ID into the agent running the job.
- task: XamariniOS@2 inputs: solutionFile: '**/*iOS.csproj' configuration: 'AppStore' packageApp: true
The Xamarin.iOS build task will only generate an .ipa package if the agent running the job has the appropriate provisioning profile and Apple certificate installed. If you enable the packageApp option and the agent does not have the appropriate apple provisioning profile(.mobileprovision) and apple certificate(.p12) the build may report succeeded but there will be no .ipa generated.
For Microsoft Hosted agents the .ipa package is by default located under path:
You can configure the output path by adding an argument to the Xamarin.iOS task as following:
- task: XamariniOS@2 inputs: solutionFile: '**/*iOS.csproj' configuration: 'AppStore' packageApp: true args: /p:IpaPackageDir="/Users/vsts/agent/2.153.2/work/1/a"
This example locates the .ipa in the Build Artifact Staging Directory ready to be pushed into Azure DevOps as an artifact to each build run.To push it into Azure DevOps simply add a Publish Artifact task to the end of your pipeline.
See Sign your mobile iOS app during CI for more information about signing and provisioning your iOS app.