Pair to Mac for Xamarin.iOS development

In this article

This guide describes how to use Pair to Mac to connect Visual Studio 2019
to a Mac build host. The same instructions apply to Visual Studio 2017.

Overview

Building native iOS applications requires access to Apple's build tools,
which only run on a Mac. Because of this, Visual Studio 2019 must connect to
a network-accessible Mac to build Xamarin.iOS applications.

You must manually open Xcode after installing so that it can add any additional components.

If you would prefer not to install Visual Studio for Mac, Visual Studio 2019
can automatically configure the Mac build host with Xamarin.iOS and Mono.
You must still install and run Xcode.
For more information, see Automatic Mac provisioning.

Enable remote login on the Mac

To set up the Mac build host, first enable remote login:

On the Mac, open System Preferences and go to the Sharing pane.

Check Remote Login in the Service list.

Make sure that it is configured to allow access for All users, or
that your Mac username or group is included in the list of allowed
users.

If prompted, configure the macOS firewall.

If you have set the macOS firewall to block incoming connections, you
may need to allow mono-sgen to receive incoming connections. An alert
appears to prompt you if this is the case.

If it is on the same network as the Windows machine, the Mac should
now be discoverable by Visual Studio 2019. If the Mac is still not
discoverable, try manually adding a Mac or take
a look at the troubleshooting guide.

Connect to the Mac from Visual Studio 2019

Now that remote login is enabled, connect Visual Studio 2019 to the Mac.

In Visual Studio 2019, open an existing iOS project or create a new one
by choosing File > New > Project and then selecting an iOS project
template.

Open the Pair to Mac dialog.

Use the Pair to Mac button iOS toolbar:

Or, select Tools > iOS > Pair to Mac.

The Pair to Mac dialog displays a list of all previously-connected
and currently-available Mac build hosts:

Select a Mac in the list. Click Connect.

Enter your username and password.

The first time you connect to any paticular Mac, you are
prompted to enter your username and password for that machine:

Tip

When logging in, use your system username rather than full name.

Pair to Mac uses these credentials to create a new SSH connection
to the Mac. If it succeeds, a key is added to the authorized_keys
file on the Mac. Subsequent connections to the same Mac will login
automatically.

Manually add a Mac

If you do not see a particular Mac listed in the Pair to Mac dialog,
add it manually:

Locate your Mac’s IP address.

Open System Preferences > Sharing > Remote Login on your Mac:

Alternatively, use the command line. In Terminal, issue this command:

$ ipconfig getifaddr en0
196.168.1.8

Depending on your network configuration, you may need to use an
interface name other than en0. For example: en1, en2, etc.

In Visual Studio 2019's Pair to Mac dialog, select Add Mac...:

Enter the Mac's IP address and click Add:

Enter your username and password for the Mac:

Tip

When logging in, use your system username rather than full name.

Click Login to connect Visual Studio 2019 to the Mac over SSH and add
it to the list of known machines.

Automatic Mac provisioning

Starting with Visual Studio 2019 version 15.6,
Pair to Mac automatically provisions a Mac with software necessary for
building Xamarin.iOS applications: Mono, Xamarin.iOS (the software
framework, not the Visual Studio for Mac IDE), and various Xcode-related
tools (but not Xcode itself).

Important

Pair to Mac cannot install Xcode; you must manually install it on the
Mac build host. It is required for Xamarin.iOS development.

Automatic Mac provisioning requires that remote login is
enabled on the Mac, and the Mac must be network-accessible to the Windows
machine. See Enabling remote login on the Mac
for more details.

Pair to Mac performs necessary software installations/updates when Visual
Studio 2017 is connecting to the
Mac.

Mono

Pair to Mac will check to make sure that Mono is installed. If it is not
installed, Pair to Mac will download and install the latest stable version
of Mono on the Mac.

Progress is indicated by various prompts, as shown by the following
screenshots (click to zoom):

Install Check

Downloading

Installing

Mono

Xamarin.iOS

Pair to Mac upgrades Xamarin.iOS on the Mac to match the version
installed on the Windows machine.

Important

Pair to Mac will not downgrade Xamarin.iOS on the Mac from alpha/beta
to stable. If you have Visual Studio for Mac installed, set your
release channel as
follows:

If you use Visual Studio 2019, select the Stable updates channel in
Visual Studio for Mac.

If you use Visual Studio 2019 Preview, select the Alpha updates
channel in Visual Studio for Mac.

Progress is indicated by various prompts, as shown by the following
screenshots (click to zoom):

Install Check

Downloading

Installing

Xamarin.iOS

Xcode tools and license

Pair to Mac will also check to determine whether Xcode has been installed
and its license accepted. While Pair to Mac does not install Xcode, it
does prompt for license acceptance, as shown in the following screenshots
(click to zoom):

Install Check

License Acceptance

Xcode

Additionally, Pair to Mac will install or update various packages
distributed with Xcode. For example:

MobileDeviceDevelopment.pkg

XcodeExtensionSupport.pkg

MobileDevice.pkg

XcodeSystemResources.pkg

The installation of these packages happens quickly and without a prompt.

Note

These tools are distinct from the Xcode Command Line Tools, which
as of macOS 10.9 are
installed with Xcode.

Troubleshooting automatic Mac provisioning

If you encounter any trouble using automatic Mac provisioning, take a look
at the Visual Studio 2019 IDE logs, stored in
%LOCALAPPDATA%\Xamarin\Logs\15.0. These logs may contain error messages
to help you better diagnose the failure or get support.

Build iOS apps from the Windows command-line

Pair to Mac supports building Xamarin.iOS applications from the command
line. For example:

The first time Pair to Mac logs in to a particular Mac build host from
either Visual Studio 2019 or the command-line, it sets up SSH keys. With these
keys, future logins will not require a username or password. Newly
created keys are stored in %LOCALAPPDATA%\Xamarin\MonoTouch.

If the ServerPassword parameter is omitted from a command-line build
invocation, Pair to Mac attempts to log in to the Mac build host
using the saved SSH keys.

Summary

This article described how to use Pair to Mac to connect Visual Studio 2019 to a
Mac build host, enabling Visual Studio 2019 developers to build native iOS
applications with Xamarin.iOS.