This Article will explain how to set up the iOS Continuous Deployment of a Xamarin application. It will describe the automated build process and deployment of a Xamarin Application and create and deploy a mobile and desktop package for deployment for iOS.
The general concept is described in the previous article Continuous Deployment of Xamarin Projects.
Step 1 – Acquiring a Mac for Building
There is a Pay-as-you-Go (or a dedicated Build Agent) plan from macincloud.com. Unfortunately, you can’t use the VSTS (Visual Studio Team Services) Build Agent plan offered because we need the build to generate the IPA file which requires all the certificate/ provisioning profile madness and therefore actual UI access.
Add the Mac as a Build Agent
The Mac needs to field the build requests from VSTS. So you have to install the build agent on it.
To create a build agent on a Mac, follow the instructions from Microsoft. It is recommended to follow the “How to run as a service” steps at the end so it survives any reboots that might be done unbeknownst to you.
If you go to your VSTS account now, you should see the Mac Build Agent in the agent pool you specified during setup, like this:
In this case, the Xamarin build agents are put in to a Xamarin queue.
If you don’t see the agent in that list with a green bar next to it you need to redo the installation of the agent on the target Mac; something didn’t go right.
Once the build agent is configured, you need to get all the certificates and provisioning profiles on the Mac. The best guide for this is the one from Xamarin.
The following will be for an Ad-Hoc distribution for the HockeyApp deployment.
Install Xamarin Studio
To build the iOS app using Xamarin.iOS it is necessary to have Xamarin Studio installed on all build agents that might service the CI request.
Step 2 – Configure the Continuous Integration build
Configure the build like the other two platforms
The important part here is the one pointed out. The agent queue.
You must select the queue into which you placed the Mac Build Agent for this one, not the Hosted queue which in this case is the Xamarin queue.
Since this build will be specific to Xamarin.iOS, it is recommended to create a separate SLN for building the iOS project. This will also work well for any developers on the team actually using a Mac (with Xamarin Studio) for development.
Target this solution in the “Xamarin.iOS” task that shows in the build definition after completing the wizard.
Remove the Xamarin Test Cloud task (unless you want use it).
Due to Xamarin’s lack of compatibility with NuGet. Xamarin ships with nuGet v2.8.5 – which has a bug in it regarding dependency evaluation which will rear its head if you choose the right (wrong?) packages.
It is possible to fix this with shell scripts!
Add a new build task to the start (like we did with the PowerShell ones) pointing at a script file:
curl -s -O https://dist.nuget.org/win-x86-commandline/v2.8.6/nuget.exe
mono nuget.exe restore App-MacOSX.sln
Save this file and push it to your repository then target it in the new build task:
The script will:
1) Pull down the v2.8.6 version of Nuget and
2) Restore the Nuget packages for the solution
The other step we need to add is to Copy and Publish Build Artifacts.
The ‘Copy Root’ part here serves as the directory which hosts iOS-specific files (remember the folder structure).
The process then pulls all resulting IPA files and puts them in a ‘drop’ folder on the Server.
Step 3 – Create the Release Definition
HockeyApp’s got great integration with iOS.
Set it up exactly as we did the Android one, but use *.ipa for ‘Binary File Path’ instead of *.apk:
And we’re done!
Once completed with all of our steps we now have a complete functioning Source Code and Version Control with Continuous Integration and Deployment working.
Check in some code to the branch you targeted in each of the 3 Build Definitions and you should see output something like:
With HockeyApp looking like:
As mentioned in the optional steps we can customize the deployment process greatly and add or remove steps when deploying our app packages. The choices can include our own internal web server for example or HockeyApp’s deployment service etc.
Since we can add PowerShell scripts to run in our process the customization options are quite numerous.
Thank you for reading, I hope this article was useful and will come in handy for any future Xamarin Developers or Deployment specialists.
Please take a look at my Continuous Deployment guides for the other Platforms as well.
Never miss an update by following us and subscribing to our monthly newsletter!