Benjamin Tam

Independent Consultant
Mobile | .NET Core | Agile

5 VSTS Hosted Mac Agent Tips For Xamarin

I had been eagerly waiting for a chance to try out the new VSTS Hosted Mac Agents, which were released in preview last November. I happily took the opportunity to do so when the Mac Mini build server at my client started becoming more of an unreliable liability. Shortly after a demo where I created a build pipeline for my client’s Xamarin app in VSTS, the necessary stakeholders approved and linked it to their existing Azure subscription for billing. Sales isn’t one of my core skills, but this was an easy sell!

If you have a new Xamarin app, then the build definition templates available with VSTS should work with minimal additional configuration. However, if there are pre-established processes involved, there could some minor speed bumps. Accordingly, I thought I would document some of the nuances and lessons learned along the way.

1. Xamarin.Android Solution Path

Out of the box, the Xamarin.Android build definition template uses a \ (back slash) in the file matching pattern to find the solution(s). This will need to change this to a / (forward slash) when using a Mac build agent, which is of course the standard delimiter on macOS. Otherwise, the default build definition will yield a false positive (i.e. green) at the NuGet restore task, but then fail at the subsequent build task as the required packages won’t be restored.

Change the back slash to a forward slash

2. Xamarin.iOS Build Tool

The Xamarin.iOS build task uses xbuild for the build tool as standard. However, xbuild has been deprecated in favour of MSBuild as of Mono 5.0.0.

Use MSBuild instead of xbuild

3. NuGet Restore

The Xamarin.iOS build task will restore NuGet packages by default. If there are packages which don’t come from NuGet, additional steps are required to first install NuGet itself before restoring packages. Conversely, the Xamarin.Android build definition template already does this.

Note that if there are packages from NuGet and one additional source, this cannot be configured simply through the UI by entering a value in Use packages from this VSTS/TFS feed and then selecting Use packages from NuGet.org. This must be done through a NuGet.Config file.

Use separate NuGet build tasks with NuGet.Config for additional packages

4. App Metadata

To automatically bump the version of the app or change the package name as part of the build, have a look at James Montemagno’s VSTS extensions.

Note that while the name of the extension in the VSTS Marketplace is Mobile App Tasks for iOS and Android, it actually comprises of 4 different tasks. After installing the extension, it is the name of the individual tasks that can be added to the build.

Use Mobile App Tasks for iOS and Android to change app metadata

5. One Build For Both iOS & Android

Currently, VSTS provide separate build definition templates for Xamarin.iOS and Xamarin.Android. You can of course have separate builds for each platform. However, I find that with cross-platform mobile projects, it is typically easier for both the developer(s) and other stakeholders to keep builds and app versions in lockstep across all platforms. My preferred approach to achieve this is to just create my own custom build definition for both platforms since a combined build template definition for both Xamarin.Android and Xamarin.iOS is not currently available.

There are separate build definition templates for Android & iOS but not a combined one