Build your Xamarin app

2016-8-45 minutes to read

In this article

VSTS | TFS 2017 Update 2

Xamarin enables you to develop a single solution and deploy it to Android, iOS, and Windows devices. Visual Studio Team Services (VSTS) and Team Foundation Server (TFS) provide a highly customizable continuous integration (CI) process to automatically build and package your Xamarin app whenever your team pushes or checks in code. In this quickstart you learn how to define your CI process.

Prerequisites

A VSTS account. If you don't have one, you can create one for free. If your team already has one, then make sure you are an administrator of the team project you want to use.

While the simplest way to try this quickstart is to use a VSTS account, you can also use a TFS server instead of a VSTS account.

You will build the sample app on Android and iOS using two build definitions in this quickstart. If you use VSTS, you can use hosted agent for Xamarin.Android, but if you use TFS or to build Xamarin.iOS, you also need a private agent. Set up a private agent and Install Xamarin on the agent machine. The Xamarin version on your dev machine and build agent machine must be at least 4.0.3 for Windows and 5.10.3 for Mac.

Get the sample code

To configure a CI build process for your app, the source code needs to be in a version control system. VSTS and TFS integrate with various version control systems such as Git in VSTS or TFS, Team Foundation Version Control (TFVC), GitHub, and Subversion.

For a simple way to follow this quickstart, get the following sample app code and put it into your own version control repository:

On the Code hub for your team project in VSTS/TFS, select the option to Import repository.

In the Import a Git repository dialog box, paste the above URL into the Clone URL text box.

Click Import to copy the sample code into your Git repo.

To fork the sample app into your own GitHub repository:

Navigate to the above GitHub repository URL in your browser.

Select Fork to create your own copy of the repository.

Set up continuous integration

A continuous integration (CI) process automatically builds and tests code every time a team member commits changes to version control. Here you'll create a CI build definition that helps your team keep the master branch clean.

You need to create two build definitions - one for Xamarin.Android and one for Xamarin.iOS.

Observe that the new build definition is automatically linked to your repository.

Select your version control repository. You'll need to authorize access to your repo.

Select Build Xamarin.Android Project task. In the properties for this task, select JDK 8 as the JDK Version, and x64 as the JDK Architecture.

Select Build solution */test.csproj task. In the properties for this task, uncheck Enabled under Control Options. There are no tests in the sample repository.

Select Xamarin Test Cloud task. Remove this task from the definition.

Click Save and queue to kick off your first build. On the Queue build dialog box, click Queue.

A new build is started. You'll see a link to the new build on the top of the page. Click the link to watch the new build as it happens.

Define your Xamarin.iOS build

Repeat the same steps as above to create another build definition, but this time select the Xamarin.iOS template.

For the Default agent queue, select the queue that includes your MAC agent.

Remove Xamanrin Test Cloud task.

Click the Variables tab and modify these variables:

BuildConfiguration = iOS Release

View the build summary

Once the build completes, select the build number to view a summary of the build.

Notice the various sections in the build summary - the source version of the commit in build details section, list of all associated changes, links to work items associated with commits, and test results.
When the build is automatically triggered by a push to your Git repository, these sections are populated with all the relevant information.

Next steps

To be able to configure your own app for iOS release, you need to make the following changes in the solution in your development environment, since the Xamarin.iOS build requires a solution configuration that builds only the Xamarin.iOS project and its dependencies.

In Visual Studio, open Solution Explorer (Keyboard: Ctrl + Alt + L).

Right-click your solution and then click Configuration Manager.

On the configuration manager dialog box open the active solution configuration drop-down menu and click New.

There's also a known issue that might cause a problem with building your Xamarin.iOS project. For example, in the build log for a Xamarin.iOS build step you might see an errors such as error : Project reference '../App1/App1.csproj' has invalid or missing guid for metadata 'Project'.

To fix this issue:

In Visual Studio, open Solution Explorer (Keyboard: Ctrl + Alt + L).

Expand your .iOS project node, and then the References node.

Right-click each reference to a portable class library and then click Remove.

Right-click the References node and then click Add Reference.

On the Reference Manager dialog box, expand Projects, and then click Solution.