Using Azure DevOps to Build and Publish your Xamarin iOS App

Hemant Bhutani
5 min readJul 4, 2019

--

Well after searching multiple articles, blogs and videos i was able to setup our new Xamarin iOS app on Azure DevOps. In this story i would like to focus on creating a Build and finally, publishing (releasing) it on TestFlight (App Store). To be honest it took me long time to create a build and at last upload it on App Store for testing purpose.

Description

One of the objectives of Azure DevOps is automating a lot of tedious work such as builds and releases. With the help of this document we would configure Build and Release pipeline for Xamarin Mobile App on Azure DevOps.

Importing/Creating your repository

1> Create a new project on Azure Devops. For the document purpose, I have created the project named “XamarinApp” and will be using the same for reference purpose in this article.

Import/Create Repository

2> Next click on “Pipeline” and select source of your Repository. Now you can either Import your Repo or create a new one. For demonstration purpose I have imported the source code from my Git Repo and named it as “XamarinApp”.

3> Once you have mentioned the URL and credentials for your repo, it will start importing files to Azure DevOps Repo. Note : This will basically create a new Repo with name “ProjectName” which would be a clone of your GIT repo.

4> The files would now appear in your new Azure Repo and can be used to create a Build Pipeline.

Before I proceed further onto the next phase (creating build pipeline), I would like to clarify another thing. While we run our iOS app from Visual Studio there are 2 ways to provision the app i.e Automatic Provisioning or Manual Provisioning. However, as per current process I would use “Manual Provisioning” so that we can utilize build agent running on Azure DevOps Servers.

Important Note: When setting up an iOS build you firstly need to select the correct agent pool from Azure DevOps. In this case select the Hosted macOS agent pool. Click on Pipeline, and select the agent pool.

Creating a Build Pipeline

1> Click on Pipeline and then click on “Create Pipeline” button to start the process. You can select YAML based pipeline if you are similar with YAML format or else click on “Classic Editor” to select the GUI based pipeline.

2> In my case I am using classic editor. Select the source of the pipeline along with the branch for which build is required.

3> To set up our Xamarin iOS build we use the available template in Azure DevOps because it contains all the necessary build tasks to create an IPA file which is Apple’s equivalent of the APK file in Android. For this purpose, I will use template name “Xamarin.iOS”.

4> Some of the tasks in the template would be in “disabled” state, however we would require them to successfully create a proper build and hence I have enabled these tasks. This includes tasks like “Install an Apple certificate”, “Install an Apple provisioning profile” etc.

5> Installing the Apple certificate :Upload your Apple P.12 certificate which differs from the .cer file along with password. Use your apple developer account to download this certificate. Instead of manually passing the password I have defined a Secret Variable in the “Variables” tab and added the value for the password. For this I created a variable name “P12password” and mentioned in as $(P12password) in password column as per the syntax.

If you are still confused about this task, please check Xamarin Tutorial https://docs.microsoft.com/en-us/xamarin/ios/get-started/installation/device-provisioning/

6> Next step is to add the required configuration for 2nd Task “Install an Apple Provisioning Profile”. Again access your Apple Developer account to download this profile.

7> Once these are completed we will be using install NuGet and NuGet Restore tasks to successfully add\create the NuGet packages.

8> During my test build I was facing some issues related to dependencies of packages and hence, I manually created a bash command to change the SDK version of Xamarin. You can try running your build without this task and if it works then no need to add run this Bash command.

Error message without using the Bash Command task.

MTOUCH : error MT2101: Can’t resolve the reference ‘System.String System.String::Trim(System.Char)’, referenced from the method ‘System.Threading.Tasks.Task`1<FFImageLoading.Work.DataResolverResult> FFImageLoading.DataResolvers.BundleDataResolver::ResolveFromBundlesAsync(System.String,System.String,FFImageLoading.Work.TaskParameter,System.Threading.CancellationToken)’ in ‘mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e’. [/Users/vsts/agent/2.153.2/work/1/s/Xamarin_Mobile/XXXXXX.iOS/xxx.iOS.csproj]

9> Build Xamarin.iOS solution : Next is the main step to BUILD the Xamarin solution by using task “Build Xamarin.iOS solution **/*.sln”. Once again, confirm your Xamarin.Forms iOS project is configured for Manual Provisioning and set the values for the Signing Identity and Provisioning profile. By selecting “Create App Package” we would be able to generate an IPA file as a part of the build. This is the main file which is installed onto devices. Do check the Values mentioned under “Signing Identity” and “Provisioning profile UUID”. No need to create or specify these under “Variables” as they are created during the build process.

For the Build tool, I am using MSBuild ( Visual Studio for Mac ) instead of xbuild.

10> And finally the predefined steps to Copy files and Publish Artifacts with default settings. No further configurations are required under this task until and unless you want to copy files at a different location.

This marks the end of our Build process wherein we are able to generate a .ipa file for further publishing on App Store or Test Flight.

--

--