Building and testing Xamarin applications
Learn how to create a continuous integration (CI) workflow in GitHub Actions to build and test your Xamarin application.
In this article
Introduction
This guide shows you how to create a workflow that performs continuous integration (CI) for your Xamarin project. The workflow you create will allow you to see when commits to a pull request cause build or test failures against your default branch; this approach can help ensure that your code is always healthy.
For a full list of available Xamarin SDK versions on the GitHub Actions-hosted macOS runners, see the README file for the version of macOS you want to use in theGitHub Actions Runner Images repository.
Prerequisites
We recommend that you have a basic understanding of Xamarin, .NET Core SDK, YAML, workflow configuration options, and how to create a workflow file. For more information, see:
Building Xamarin.iOS apps
The example below demonstrates how to change the default Xamarin SDK versions and build a Xamarin.iOS application.
name:BuildXamarin.iOSappon: [push]jobs:build:runs-on:macos-lateststeps:-uses:actions/checkout@v5-name:SetdefaultXamarinSDKversionsrun:| $VM_ASSETS/select-xamarin-sdk-v2.sh --mono=6.12 --ios=14.10-name:SetdefaultXcode12.3run:| XCODE_ROOT=/Applications/Xcode_12.3.0.app echo "MD_APPLE_SDK_ROOT=$XCODE_ROOT" >> $GITHUB_ENV sudo xcode-select -s $XCODE_ROOT-name:Setup.NETCoreSDK5.0.xuses:actions/setup-dotnet@v4with:dotnet-version:'5.0.x'-name:Installdependenciesrun:nugetrestore<sln_file_path>-name:Buildrun:msbuild<csproj_file_path>/p:Configuration=Debug/p:Platform=iPhoneSimulator/t:RebuildBuilding Xamarin.Android apps
The example below demonstrates how to change default Xamarin SDK versions and build a Xamarin.Android application.
name:BuildXamarin.Androidappon: [push]jobs:build:runs-on:macos-lateststeps:-uses:actions/checkout@v5-name:SetdefaultXamarinSDKversionsrun:| $VM_ASSETS/select-xamarin-sdk-v2.sh --mono=6.10 --android=10.2-name:Setup.NETCoreSDK5.0.xuses:actions/setup-dotnet@v4with:dotnet-version:'5.0.x'-name:Installdependenciesrun:nugetrestore<sln_file_path>-name:Buildrun:msbuild<csproj_file_path>/t:PackageForAndroid/p:Configuration=DebugSpecifying a .NET version
To use a preinstalled version of the .NET Core SDK on a GitHub-hosted runner, use thesetup-dotnet action. This action finds a specific version of .NET from the tools cache on each runner, and adds the necessary binaries toPATH. These changes will persist for the remainder of the job.
Thesetup-dotnet action is the recommended way of using .NET with GitHub Actions, because it ensures consistent behavior across different runners and different versions of .NET. If you are using a self-hosted runner, you must install .NET and add it toPATH. For more information, see thesetup-dotnet action.