Build your Xamarin.iOS application with Azure DevOps
During the development process it is important that you provide a test version for your testers to get feedback and improve your application. It is also important that you don’t create the corresponding packages on your machine instead use a pipeline.
Introduction
I’ve already published a post about creating a pipeline on Azure DevOps to build your Xamarin.Android application. This post will now explain how you can build your Xamarin.iOS application on an Azure DevOps service. If your code is published on your Azure DevOps server, we can start to setup your pipeline
Preparation
To be able to sign the iOS build, you need to have a paid developer account from Apple. You can apply to an account on the website developer.apple.com. You also need a Mac machine, because you need to create a developer certificate on that machine. Now you should be able to create a P12 certificate file and a provisioning profile.
I’m not explaining how you can get these two files, but if you are interested in knowing how to get these files, just let me know in the comments and I will write another post explaining this process.
To go on with this post I assume that you have the P12 certificate file with the corresponding password and a provisioning profile file.
Uploading the files to Azure DevOps
We need these two files in our pipeline. We open Azure DevOps, navigate to our project and then to Library
, which is part of the Pipelines
tab. We switch to Secure files
. The following screenshots already includes the settings for the Android pipeline from my other post.
Now we click on + Secure file
and select the provisioning profile file first and then accept the upload by clicking OK
.
We need to repeat this process with the P12 certificate file.
Now we can switch to the Variable groups
tab. From my last post I already have a variable group called variables
. If you don’t have this group, you can easily create this and call it variables
. We need to create three new variables: AppleCertificate-FileName
, AppleCertificate-Password
and ProvisioningProfile-FileName
. The variable AppleCertificate-Password
should be created as a secure variable, so nobody can see the password. The FileName
variable should contain the corresponding file names of the uploaded files.
Creating the pipeline
It is possible to combine the process of creating the Android and the iOS version in one pipeline. But I will create a separate one for the iOS build.
We select the Pipelines
tab in the left menu. To create a new pipeline we are using the blue button (labeled New pipeline
). In the first step we have to provide the location from our code. In my case I’m storing the code in the Azure Repos Git
, but you can also use your code from GitHub
, BitBucket
or every other Git or Subversion source.
To continue I’m selecting Azure Repos Git
. Now all possible repositories should be listed. In my case it is just one repository (Xamarin Playground
), which I will select.
In the next step Azure DevOps provides some predefined templates for different pipelines. These are pretty basic, so I’m using Starter pipeline
here to get a basic structure of the YAML file.
An editor will be displayed containing the current version of the YAML file.
Now we need to update this file to be able to build our application and create the IPA file. IPA is an acronoym for iOS App Store Package and is an archive file which stores our iOS app.
The following code snippet shows the complete pipeline, but don’t worry I will explain it afterwards.
The top is defining the metadata. In my case I just want to listen to changes on the main
branch, but you can define all your possible branches, like dev
or staging
as well.
The keyword variables
connects our created varibale group to the pipeline. Make sure that the group
value is matching the name of your variable group.
I’m using Jobs
in this pipeline, because later I want to add the steps to create the Android version into this pipeline as well. But for now we just have one job called BuildiOS
.
Due to the fact that we want to create an iOS app, we need to use a Mac machine to build the package. Luckily Microsoft provides a hosted agent running on MacOS. This is the reason that we use macOS-latest
.
The next section contains some variables. In our case it is only the current build configuration.
Now the magic happens, because we are defining the steps for our pipeline. First of all we need to make sure that NuGet
is installed. Afterwards we do a NuGet restore
for our solution to install all the needed NuGet packages.
In the next step we need to download the secure files. Due to the fact that we have two files, we also need to DownloadSecureFile@1
tasks. We use the the values from our variable group to provide the corresponding file names.
Next step is to install the files. First we install the P12 certificate file by using a InstallAppleCertificate@2
task. We need to provide once again the file name and the corresponding password from our variables. We although need to install the provisioning file by using the InstallAppleProvisioningProfile@1
task. Here we need to pass settings where the profile should be saved and also the name of the file. We also set the removeFiles
to true
to make sure that the profile will be removed at the end.
Now it is time to build the app. Therefore we are using the XamariniOS@2
task. If you want to create a signed IPA file it is important that you set signingIdentity
and signingProvisioningProfileID
which are values created by the install tasks of the files.
The next two steps are copying and publishing the corresponding IPA file.
Let’s run the pipeline
Now it is time to check the pipeline. Just hit Save
and decide if you want to create a separate branch with your pipeline. Now let’s run the pipeline.
As you can see the pipeline succeeded and if you click on the link 1 published
in the section Related
on the summary page you have access to the IPA file.
Combine Android and iOS pipeline
Now that we have two separate pipelines for our application in place, it is time to combine these pipelines into one pipeline, which will create the APK and AAB files for Android and the IPA file for iOS. We just need to combine the jobs
of the two pipelines into one pipeline.
If we now run this pipeline you see that Android and iOS are build during the run of the pipeline.
After the pipeline succeeded, you click on the link 1 published
in the section Related
on the summary page and you have access to the APK, the AAB and the IPA file.
Conclusion
In this post I’ve showed how you can setup a pipeline to build and publish your Xamarin.iOS application using Azure DevOps. This pipeline creates the needed IPA file. I’ve also created a combined pipeline creating the needed files for Android and iOS.