{"meta":{"title":"Building and testing Xamarin applications","intro":"Learn how to create a continuous integration (CI) workflow in GitHub Actions to build and test your Xamarin application.","product":"GitHub Actions","breadcrumbs":[{"href":"/en/actions","title":"GitHub Actions"},{"href":"/en/actions/tutorials","title":"Tutorials"},{"href":"/en/actions/tutorials/build-and-test-code","title":"Build and test code"},{"href":"/en/actions/tutorials/build-and-test-code/xamarin-apps","title":"Xamarin apps"}],"documentType":"article"},"body":"# Building and testing Xamarin applications\n\nLearn how to create a continuous integration (CI) workflow in GitHub Actions to build and test your Xamarin application.\n\n## Introduction\n\nThis 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.\n\nFor 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 the [GitHub Actions Runner Images repository](https://github.com/actions/runner-images/tree/main/images/macos).\n\n## Prerequisites\n\nWe 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:\n\n* [Workflow syntax for GitHub Actions](/en/actions/using-workflows/workflow-syntax-for-github-actions)\n* [Getting started with .NET](https://dotnet.microsoft.com/learn)\n* [Learn Xamarin](https://dotnet.microsoft.com/learn/xamarin)\n\n## Building Xamarin.iOS apps\n\nThe example below demonstrates how to change the default Xamarin SDK versions and build a Xamarin.iOS application.\n\n```yaml\nname: Build Xamarin.iOS app\n\non: [push]\n\njobs:\n  build:\n\n    runs-on: macos-latest\n\n    steps:\n    - uses: actions/checkout@v6\n    - name: Set default Xamarin SDK versions\n      run: |\n        $VM_ASSETS/select-xamarin-sdk-v2.sh --mono=6.12 --ios=14.10\n\n    - name: Set default Xcode 12.3\n      run: |\n        XCODE_ROOT=/Applications/Xcode_12.3.0.app\n        echo \"MD_APPLE_SDK_ROOT=$XCODE_ROOT\" >> $GITHUB_ENV\n        sudo xcode-select -s $XCODE_ROOT\n\n    - name: Setup .NET Core SDK 5.0.x\n      uses: actions/setup-dotnet@v4\n      with:\n        dotnet-version: '5.0.x'\n\n    - name: Install dependencies\n      run: nuget restore <sln_file_path>\n\n    - name: Build\n      run: msbuild <csproj_file_path> /p:Configuration=Debug /p:Platform=iPhoneSimulator /t:Rebuild\n```\n\n## Building Xamarin.Android apps\n\nThe example below demonstrates how to change default Xamarin SDK versions and build a Xamarin.Android application.\n\n```yaml\nname: Build Xamarin.Android app\n\non: [push]\n\njobs:\n  build:\n\n    runs-on: macos-latest\n\n    steps:\n    - uses: actions/checkout@v6\n    - name: Set default Xamarin SDK versions\n      run: |\n        $VM_ASSETS/select-xamarin-sdk-v2.sh --mono=6.10 --android=10.2\n\n    - name: Setup .NET Core SDK 5.0.x\n      uses: actions/setup-dotnet@v4\n      with:\n        dotnet-version: '5.0.x'\n\n    - name: Install dependencies\n      run: nuget restore <sln_file_path>\n\n    - name: Build\n      run: msbuild <csproj_file_path> /t:PackageForAndroid /p:Configuration=Debug\n```\n\n## Specifying a .NET version\n\nTo use a preinstalled version of the .NET Core SDK on a GitHub-hosted runner, use the `setup-dotnet` action. This action finds a specific version of .NET from the tools cache on each runner, and adds the necessary binaries to `PATH`. These changes will persist for the remainder of the job.\n\nThe `setup-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 to `PATH`. For more information, see the [`setup-dotnet`](https://github.com/marketplace/actions/setup-net-core-sdk) action."}