|
| 1 | +--- |
| 2 | +title: Building and testing Xamarin applications |
| 3 | +intro: You can create a continuous integration (CI) workflow in GitHub Actions to build and test your Xamarin application. |
| 4 | +product: '{% data reusables.gated-features.actions %}' |
| 5 | +versions: |
| 6 | + free-pro-team: '*' |
| 7 | + enterprise-server: '>=2.22' |
| 8 | + github-ae: '*' |
| 9 | +type: 'tutorial' |
| 10 | +topics: |
| 11 | + - 'CI' |
| 12 | + - 'Xamarin' |
| 13 | + - 'Xamarin.iOS' |
| 14 | + - 'Xamarin.Android' |
| 15 | + - 'Android' |
| 16 | + - 'iOS' |
| 17 | +--- |
| 18 | + |
| 19 | +{% data reusables.actions.enterprise-beta %} |
| 20 | +{% data reusables.actions.enterprise-github-hosted-runners %} |
| 21 | +{% data reusables.actions.ae-beta %} |
| 22 | + |
| 23 | +### Introduction |
| 24 | + |
| 25 | +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. |
| 26 | + |
| 27 | +{% data variables.product.prodname_actions %}-hosted macOS runner stores Xamarin SDK versions and the associated Mono versions as a set of symlinks to Xamarin SDK locations that are available by a single bundle symlink. For a full list of available Xamarin SDK versions and their corresponding bundles, see the runners documentation: |
| 28 | + |
| 29 | +* [macOS 10.15](https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md#xamarin-bundles) |
| 30 | +* [macOS 11.0](https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11.0-Readme.md#xamarin-bundles) |
| 31 | + |
| 32 | +{% data reusables.github-actions.macos-runner-preview %} |
| 33 | + |
| 34 | +### Prerequisites |
| 35 | + |
| 36 | +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: |
| 37 | + |
| 38 | +- "[Workflow syntax for {% data variables.product.prodname_actions %}](/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions)" |
| 39 | +- "[Getting started with .NET](https://dotnet.microsoft.com/learn)" |
| 40 | +- "[Learn Xamarin](https://dotnet.microsoft.com/learn/xamarin)" |
| 41 | + |
| 42 | +### Bulding Xamarin.iOS apps |
| 43 | + |
| 44 | +The example below demonstrates how to change the default Xamarin bundle and build a Xamarin.iOS application. |
| 45 | + |
| 46 | +{% raw %} |
| 47 | +```yaml |
| 48 | +name: Build Xamarin.iOS app |
| 49 | + |
| 50 | +on: [push] |
| 51 | + |
| 52 | +jobs: |
| 53 | + build: |
| 54 | + |
| 55 | + runs-on: macos-latest |
| 56 | + |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v2 |
| 59 | + - name: Select default Xamarin bundle to 6_12_6 |
| 60 | + run: | |
| 61 | + XAMARIN_SDK=6_12_6 |
| 62 | + $VM_ASSETS/select-xamarin-sdk.sh $XAMARIN_SDK |
| 63 | + |
| 64 | + - name: Set default Xcode 12.3 |
| 65 | + run: | |
| 66 | + XCODE_ROOT=/Applications/Xcode_12.3.0.app |
| 67 | + echo "MD_APPLE_SDK_ROOT=$XCODE_ROOT" >> $GITHUB_ENV |
| 68 | + sudo xcode-select -s $XCODE_ROOT |
| 69 | +
|
| 70 | + - name: Setup .NET Core SDK 5.0.x |
| 71 | + uses: actions/setup-dotnet@v1 |
| 72 | + with: |
| 73 | + dotnet-version: '5.0.x' |
| 74 | + |
| 75 | + - name: Install dependencies |
| 76 | + run: nuget restore <sln_file_path> |
| 77 | + |
| 78 | + - name: Build |
| 79 | + run: msbuild <csproj_file_path> /p:Configuration=Debug /p:Platform=iPhoneSimulator /t:Rebuild |
| 80 | +``` |
| 81 | +{% endraw %} |
| 82 | +
|
| 83 | +### Bulding Xamarin.Android apps |
| 84 | +
|
| 85 | +The example below demonstrates how to change default the Xamarin bundle and build a Xamarin.Android application. |
| 86 | +
|
| 87 | +{% raw %} |
| 88 | +```yaml |
| 89 | +name: Build Xamarin.Android app |
| 90 | + |
| 91 | +on: [push] |
| 92 | + |
| 93 | +jobs: |
| 94 | + build: |
| 95 | + |
| 96 | + runs-on: macos-latest |
| 97 | + |
| 98 | + steps: |
| 99 | + - uses: actions/checkout@v2 |
| 100 | + - name: Select default Xamarin bundle to 6_12_6 |
| 101 | + run: | |
| 102 | + XAMARIN_SDK=6_12_6 |
| 103 | + $VM_ASSETS/select-xamarin-sdk.sh $XAMARIN_SDK |
| 104 | +
|
| 105 | + - name: Setup .NET Core SDK 5.0.x |
| 106 | + uses: actions/setup-dotnet@v1 |
| 107 | + with: |
| 108 | + dotnet-version: '5.0.x' |
| 109 | + |
| 110 | + - name: Install dependencies |
| 111 | + run: nuget restore <sln_file_path> |
| 112 | + |
| 113 | + - name: Build |
| 114 | + run: msbuild <csproj_file_path> /t:PackageForAndroid /p:Configuration=Debug |
| 115 | +``` |
| 116 | +{% endraw %} |
| 117 | +
|
| 118 | +### Specifying a .NET version |
| 119 | +
|
| 120 | +To use a preinstalled version of the .NET Core SDK on a {% data variables.product.prodname_dotcom %}-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. |
| 121 | + |
| 122 | +The `setup-dotnet` action is the recommended way of using .NET with {% data variables.product.prodname_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. |
0 commit comments