This article shows how to build, and test Xamarin iOS applications using Visual Studio. It will explain how to use Visual Studio to create new iOS projects, build an iOS application and then compile, test and debug using a networked-Mac to host Apple’s compiler and simulator, and Xamarin’s build toolchain.
Xamarin for Windows allows iOS applications to be written and tested within Visual Studio, with a networked Mac providing the build and deployment service.
This article covers the steps to install and configure the Xamarin.iOS tools on each computer, in order to build iOS applications using Visual Studio.
Developing for iOS inside Visual Studio provides a number of benefits:
- Creation of a single cross platform solution for iOS, Android and Windows applications.
- Using your favourite Visual Studio tools (such as Resharper and Team Foundation Server ) for all your cross-platform projects, including iOS source code.
Using the familiar (for existing Visual Studio developers) code editor, keyboard shortcuts, etc.
Requirements & Installation
There are a few requirements that must be adhered to when developing for iOS on Visual Studio. As briefly mentioned in the overview, a Mac is required to compile the .ipk file, and applications cannot be deployed to a device without Apple’s certificates and code-signing tools. The iOS simulator can also only be used on a Mac.
There are a number of configuration options available, so you can decide which works best for your development needs. These are listed below:
- Use a Mac as your main development Machine and run a Windows Virtual Machine with Visual Studio installed. We recommend using VM software such as Parallels or VMWare .
- Use a Mac just as a Build Host. In this sceanario it would be simply connected to the same network as a Windows machine with the tools installed
In either case, you should follow these steps:
- Install the Xamarin.iOS tools on your Mac host and activate your license
- Configure your Mac
- Install Xamarin tools on Windows
To develop with Xamarin in Visual Studio, you must be using at least Visual Studio 2010 Professional or higher. Xamarin will not work with Express Editions of Visual Studio, as they do not support add-ins.
The iOS Designer is available in Xamarin 3 and above.
Visual Studio Features for iOS
This section introduces the new Visual Studio features that support Xamarin iOS development. These include:
- Build Host Settings
- Visual Studio Toolbar
- Creating new iOS applications
- iOS Designer
iOS Project Properties
Build Host Settings
Go to Tools > Options in Visual Studio and open the Xamarin > iOS Settings panel to access the iOS Mac Build Host settings. Choose the section to see this screen:
You can change the Mac Build Host by clicking the Find Mac Build Host button. The following screen is displayed to update the Mac Build Host:
* The version of Xamarin.iOS being used with VisualStudio must be the same as on the Mac. The simplest method to keep them in sync is to have both machines running on the same branch (e.g. both on the Stable release branch). *
Visual Studio Toolbar Overview
The Xamarin iOS for Visual Studio plug-in adds an item to the Standard toolbar, plus the new iOS toolbar. The functions of these toolbars are explained below.
The controls relevant to Xamarin iOS development are circled in red.
- Start - Starts debugging or running the application on the selected platform. The Mac Build Host must be connected (see the status indicator in the iOS toolbar). - Solution Configurations - Allows you to select the configuration to use (eg. Debug, Release, Ad-Hoc, AppStore). - Solution Platforms - Allows you to select iPhone or iPhoneSimulator for deployment.
The iOS Toolbar in Visual Studio looks similar in each version of Visual Studio. These are all shown below:
Visual Studio 2010:
Visual Studio 2012:
Visual Studio 2013:
In all versions, the Toolbar contains the these items:
Each item is explained below:
- Target iOS Device drop down - Use this to choose which simulator or device to deploy your application to. The contents of this list changes depending on the Solution Platform selected in the Standard toolbar.
- Connected to Remote Server indicator - Will be green when a Mac Build Host is available and connected; red if not.
- Refresh Server Info - Refresh Mac Build Host information, such as after a device is attached.
- Show IPA File on Build Server - Opens the Finder on the Mac to the location of the application’s IPA output file.
- Clean Remote Log - Cleans the log on the Mac Build Host.
- Show iOS Simulator - Brings the iOS Simulator window to the front on the Mac Build Host.
iOS Output Options
There are options in the Output pane that you can view to discover build and deployment messages and errors.
- Mac Server Log – Contains detailed build and deployment information from the remotely connected Mac.
- Debug – Contains the debug output from the application, as with any Visual Studio project.
iOS Project Properties
Visual Studio’s Project Properties will let you configure your iOS application, as shown in the screenshot below:
iOS Bundle Signing - connects to the Mac Build Host to populate the code signing identities and provisioning profiles.
iOS IPA Options - the IPA file will be saved on the Mac Build Host’s file system.
iOS Application - Application settings including the bundle identifier, support orientations and default screen images.
iOS Run Options - Configure additional parameters.
iOS Crash Reporting - TestFlight crash reporting support, same as Xamarin Studio for OS X.
Creating New Project for iOS Applications
Creating a new iOS project from within Visual Studio is just like any other project type. Selecting File > New Project will open the dialog shown below illustrating some of the templates available for creating a new iOS project:
Storyboard files can be edited in Visual Studio using the iOS Designer. To create a Storyboard, choose the one of the Storyboard templates. This will generate a
MainStoryboard.storyboard file in the Solution Explorer as illustrated by the screenshot below:
To start creating or editing your Storyboard, double-click on
MainStoryboard.storyboard to open it in the iOS Designer:
To add objects to your view, use the Toolbox pane to drag and drop items onto your Design Surface. The Toolbox can be added by selecting View > Toolbox, if not already added. Object propties can be modified, their layouts adjusted and events can be created by using the Properties pane, as illustrated below:
Running & Debugging iOS Applications
Set debugging stops
Start debugging, and use the simulator or device to navigate your application to a breakpoint. When a breakpoint is hit the line will be highlighted and Visual Studio’s normal debugging behavior is enabled: you can step into, over or out of the code, examine local variables or use the Immediate Window.
This screenshot shows the iOS Simulator running next to Visual Studio using Parallels on OS X.
Examine local variables
This article described how to use Xamarin iOS for Visual Studio. It listed the various features available for creating, building and testing an iOS app from within Visual Studio and walked through building and debugging a simple iOS application.