Build your Xamarin app

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.


  • 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.

    Build Hosted agents On-premises Windows agent On-premises OSX or Linux agent
    Xamarin.Android Yes Yes (with Xamarin installed) Yes (with Xamarin installed)
    Xamarin.iOS No No Yes (with Xamarin installed)
    UWP Yes Yes (Windows 10) No

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:

To import the sample app into a Git repo in VSTS or TFS:

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

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

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

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.

Define your Xamarin.Android build

  1. Create a new build definition.

    Navigate to the Files tab of the Code hub, and then click Set up build.

    Screenshot showing button to set up build for a repository

    You are taken to the Build & Release hub and asked to Select a template for the new build definition.

  2. In the right panel, click Xamarin.Android, and then click Apply.

    You now see all the tasks that were automatically added to the build definition by the template. These are the steps that will automatically run every time you check in code.

  3. For the Default agent queue:

    • VSTS: Select Hosted VS2017. This is how you can use our pool of agents that have the software you need to build your app.

    • TFS: Select a queue that includes a Windows build agent.

  4. Click Get sources and then:

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

  5. 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.

  6. 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.

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

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

  9. 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.

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

  2. Remove Xamanrin Test Cloud task.

  3. Click the Variables tab and modify these variables:

    • BuildConfiguration = iOS Release

View the build summary

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

    Navigate to build summary

  2. 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.

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

  2. Right-click your solution and then click Configuration Manager.

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

  4. On the new solution configuration dialog box:

    • For Name, enter iOS Release

    • Open Copy settings from drop-down menu and select Release.

    • Clear the Create new project configurations dialog box.

  5. Open the Active solution platform drop-down menu:

    1. Select iPhoneSimulator and clear the check boxes on all rows except your Xamarin.iOS project and any projects (for example, portable class libraries) it depends on.

    2. Repeat this step for iPhone.

  6. File -> Save All (Keyboard: Ctrl + Shift + S).

  7. Check in your changes.

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:

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

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

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

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

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

  6. Select the portable class library projects you removed and click OK.

  7. File -> Save All (Keyboard: Ctrl + Shift + S).

  8. Check in your changes.