- Installing Xamarin.iOS on Windows
- Overview
- Setup
- Overview
- Setup
- Настройка Visual Studio при разработке приложений для iOS Configuring Visual Studio for iOS development
- Использование соответствующих версий Xamarin.iOS Using matching Xamarin.iOS versions
- Панель инструментов iOS iOS toolbar
- Раскрывающееся меню «Платформы решения» Solution Platforms drop-down menu
- Introduction to Xamarin.iOS for Visual Studio
- Requirements and Installation
- Connecting to the Mac
- Visual Studio Toolbar Overview
- Standard Toolbar
- iOS Toolbar
- iOS Output Options
- Output Window
- iOS Project Properties
- Creating a New Project for iOS Applications
- Running & Debugging iOS Applications
- Device Logging
- Set Debugging Stops
- Examine Local Variables
- Summary
Installing Xamarin.iOS on Windows
This article describes how to set up a Windows machine and a Mac build host for Xamarin.iOS development.
Overview
To build Xamarin.iOS apps with Visual Studio 2019 on Windows, you will need:
A Windows machine with Visual Studio 2019 installed. This can be a physical or a virtual machine.
A network-accessible Mac set up with Apple’s build tools and Xamarin.iOS. Visual Studio 2019 accesses this machine over a network connection to use Apple’s build tools, which are required for compiling native iOS applications.
Don’t have access to a Mac?
If you do not have access to a Mac, you can use MacinCloud or MacStadium; both services provide cloud-based Mac hardware that you can use to build Xamarin.iOS projects.
Setup
To get set up for Xamarin.iOS development in Visual Studio 2019, follow these steps:
Set up Windows (Install Visual Studio 2019)
Xamarin.iOS works with Visual Studio 2019 Community, Professional, and Enterprise editions, on a standalone or virtual machine.
Set up Mac (Install Xcode and Visual Studio for Mac)
To build, debug, and sign iOS applications for distribution, Visual Studio 2019 must have network access to a Mac build host configured with both Apple’s developer tools (Xcode) and Xamarin.iOS.
If you would prefer not to install Visual Studio for Mac, Visual Studio 2019 can automatically configure, the Mac build host with the software necessary to build Xamarin.iOS applications. For more information, see Automatic Mac provisioning.
Pair to Mac (Connect Visual Studio 2019 to the Mac)
For Visual Studio 2019 to use the iOS build tools on the Mac, the two machines must connect over a network.
Overview
To build Xamarin.iOS apps with Visual Studio 2017 on Windows, you will need:
A Windows machine with Visual Studio 2017 installed. This can be a physical or a virtual machine.
A network-accessible Mac set up with Apple’s build tools and Xamarin.iOS. Visual Studio 2017 accesses this machine over a network connection to use Apple’s build tools, which are required for compiling native iOS applications.
Setup
To get set up for Xamarin.iOS development in Visual Studio 2017, follow these steps:
Set up Windows (Install Visual Studio 2017)
Xamarin.iOS works with Visual Studio 2017 Community, Professional, and Enterprise editions, on a standalone or virtual machine.
Set up Mac (Install Xcode and Visual Studio for Mac)
To build, debug, and sign iOS applications for distribution, Visual Studio 2017 must have network access to a Mac build host configured with both Apple’s developer tools (Xcode) and Xamarin.iOS.
If you would prefer not to install Visual Studio for Mac, starting with Visual Studio 2017 version 15.6, Visual Studio 2017 can automatically configure the Mac build host with the software necessary to build Xamarin.iOS applications. For more information, see Automatic Mac provisioning.
Pair to Mac (Connect Visual Studio 2017 to the Mac)
For Visual Studio 2017 to use the iOS build tools on the Mac, the two machines must connect over a network.
Настройка Visual Studio при разработке приложений для iOS Configuring Visual Studio for iOS development
В этой статье описываются различные параметры конфигурации Xamarin.iOS для Visual Studio. This article describes various Xamarin.iOS configuration options for Visual Studio.
Использование соответствующих версий Xamarin.iOS Using matching Xamarin.iOS versions
Среда Visual Studio 2019 или Visual Studio 2017 должна использовать ту же версию Xamarin.iOS, которая установлена на узле сборки Mac. Visual Studio 2019 or Visual Studio 2017 must use the same version of Xamarin.iOS that is installed on the Mac build host. Для этого должны выполняться указанные ниже требования. To make sure this is true:
Если вы используете Visual Studio 2019 или Visual Studio 2017, выберите стабильный канал обновлений в Visual Studio для Mac. If you use Visual Studio 2019 or Visual Studio 2017, select the Stable updates channel in Visual Studio for Mac.
Если вы используете предварительную версию Visual Studio 2019, выберите альфа-канал обновлений в Visual Studio для Mac. If you use Visual Studio 2019 Preview, select the Alpha updates channel in Visual Studio for Mac.
Начиная с Visual Studio 2017 версии 15.6 система Visual Studio 2017 автоматически определяет, использует ли узел сборки Mac ту же версию Xamarin.iOS, что и Windows. Starting with Visual Studio 2017 version 15.6, Visual Studio 2017 automatically detects if the Mac build host is using the same version of Xamarin.iOS as Windows. В случае несовпадения версий Visual Studio 2017 предлагает удаленно установить правильную версию на узле сборки Mac. If there is a version mismatch, Visual Studio 2017 offers to remotely install the correct version on the Mac build host. Дополнительные сведения см. в разделе Автоматическая подготовка Mac руководства Связывание с компьютером Mac. For more information, take a look at the Automatic Mac provisioning section of the Pair to Mac guide.
Панель инструментов iOS iOS toolbar
Когда проект iOS открыт в Visual Studio 2019 или Visual Studio 2017, должна отображаться панель инструментов iOS. When an iOS project is open in Visual Studio 2019 or Visual Studio 2017, the iOS toolbar should be visible. По умолчанию она содержит четыре кнопки, которые можно использовать для разработки Xamarin.iOS. By default, it contains four buttons that are useful for Xamarin.iOS development:
- Связать с Mac — открывает диалоговое окно связывания с компьютером Mac. Pair to Mac – Opens the Pair to Mac dialog. Включена, если проект iOS открыт в Visual Studio 2019 или Visual Studio 2017. Enabled when an iOS project is open in Visual Studio 2019 or Visual Studio 2017.
- Показать симулятор iOS — на узле сборки Mac окно симулятора iOS открывается на переднем плане. Show iOS Simulator – On the Mac build host, brings the iOS Simulator to the front. Включена, если проект iOS открыт в Visual Studio 2019 или Visual Studio 2017. Enabled when an iOS project is open in Visual Studio 2019 or Visual Studio 2017.
- Журнал устройств — открывает окно, в котором можно проверять журналы устройств. Device Log – Brings up a window that allows you to inspect device logs. Включена, если проект iOS открыт в Visual Studio 2019 или Visual Studio 2017. Enabled when an iOS project is open in Visual Studio 2019 or Visual Studio 2017.
- Показать IPA-файл на сервере сборки — открывает на узле сборки Mac окно, показывающее расположение IPA-файла для приложения. Show IPA File on Build Server – Opens a window on the Mac build host, showing the location of the .ipa file for the app. Включается после завершения сборки, для которой был создан IPA-файл. Enabled after completing a build for which an .ipa was created.
Если эта панель инструментов не отображается, откройте меню Вид в Visual Studio 2019 или Visual Studio 2017 и выберите Панели инструментов > iOS. If this toolbar does not appear, open the View menu in Visual Studio 2019 or Visual Studio 2017, and choose Toolbars > iOS:
Раскрывающееся меню «Платформы решения» Solution Platforms drop-down menu
Раскрывающееся меню Платформы решения позволяет выбрать для следующей сборки целевое физическое устройство или симулятор. The Solution Platforms drop-down menu allows you to choose whether your next build will target a physical device or a simulator.
Чтобы это раскрывающееся меню всегда отображалось на стандартной панели инструментов, выполните следующие действия. To make sure this drop-down menu is visible on the Standard toolbar:
- В Visual Studio 2019 или Visual Studio 2017 щелкните стрелку «вниз» в правом крайнем углу стандартной панели инструментов. In Visual Studio 2019 or Visual Studio 2017, click the down arrow at the right edge of the Standard toolbar.
- Выберите пункт Добавить или удалить кнопки Choose Add or Remove Buttons
- Убедитесь, что флажок Платформы решения установлен: Make sure the Solution Platforms item is checked:
При открытии проекта iOS панели инструментов Стандартная и iOS должны выглядеть как на следующем снимке экрана: With an iOS project open, the Standard and iOS toolbars should now resemble the following screenshot:
Introduction to Xamarin.iOS for Visual Studio
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 to build iOS applications using Visual Studio.
Developing for iOS inside Visual Studio provides a number of benefits:
- Creation of cross-platform solutions for iOS, Android and Windows applications.
- Using your favorite Visual Studio tools (such as Resharper and Team Foundation Server) for all your cross-platform projects, including iOS source code.
- Work with a familiar IDE, while taking advantage of Xamarin.iOS bindings of all Apple’s APIs.
Requirements and Installation
There are a few requirements that must be adhered to when developing for iOS in Visual Studio. As briefly mentioned in the overview, a Mac is required to compile IPA files, and applications cannot be deployed to a device without Apple’s certificates and code-signing tools.
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 scenario it would be connected to the same network as a Windows machine with the necessary tools installed.
In either case, you should follow these steps:
Connecting to the Mac
To connect Visual Studio to your Mac build host, follow the instructions in the Pair to Mac guide.
Visual Studio Toolbar Overview
Xamarin iOS for Visual Studio adds items to the Standard toolbar and to the new iOS toolbar. The functions of these toolbars are explained below.
Standard Toolbar
The controls relevant to Xamarin iOS development are circled in red:
- Start — Starts debugging or running the application on the selected platform. There must be a connected Mac (see the status indicator in the iOS toolbar).
- Solution Configurations – Allows you to select the configuration to use (e.g., Debug, Release).
- Solution Platforms — Allows you to select iPhone or iPhoneSimulator for deployment.
iOS Toolbar
The iOS Toolbar in Visual Studio looks similar in each version of Visual Studio. These are all shown below:
Each item is explained below:
- Mac Agent/Connection Manager – Displays the Xamarin Mac Agent dialog box. This icon will appear orange when connecting, and green when connected.
- Show iOS Simulator – Brings the iOS Simulator window to the front on the Mac.
- Show IPA File on Build Server – Opens Finder on the Mac to the location of the application’s IPA output file.
iOS Output Options
Output Window
There are options in the Output pane that you can view to discover build, deployment, and connection messages and errors.
The screenshot below shows the available output windows, which may differ depending on your project type:
Xamarin – This contains information relating solely to Xamarin, such as the connection to the Mac and activation status.
Xamarin Diagnostics – This shows more detailed information about your Xamarin project, such as the interaction with and for Android.
Other default Visual Studio Output panes like Debug and Build are still available inside the Output view and are used for Debugging Output and MSBuild Output:
Debug
Build & Build Order
iOS Project Properties
Visual Studio’s Project Properties can be accessed by right-clicking on the Project name and selecting Properties in the context menu. This will let you configure your iOS application, as shown in the screenshot below:
iOS Bundle Signing – connects to the Mac to populate the code signing identities and provisioning profiles:
iOS IPA Options – the IPA file will be saved on the Mac’s file system:
iOS Run Options – Configure additional parameters:
Creating a New Project for iOS Applications
Creating a new iOS project from within Visual Studio is done just like any other project type. Selecting File > New Project will open the dialog shown below, illustrating some of the project types available for creating a new iOS project:
Selecting iOS App (Xamarin) will show the following templates for creating a new Xamarin.iOS application:
Storyboard and .xib 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 Main.storyboard file in the Solution Explorer as illustrated by the screenshot below:
To start creating or editing your Storyboard, double-click on Main.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 properties can be modified, their layouts adjusted, and events can be created by using the Properties pane, as illustrated below:
For more information on using the iOS designer, refer to the Designer guides.
Running & Debugging iOS Applications
Device Logging
In Visual Studio 2017, the Android and iOS log pads are unified.
The new Device Log tool window for Visual Studio allows to show logs for Android and iOS devices. It can be shown by executing any of the following commands:
- View > Other Windows > Device Log
- Tools > iOS > Device Log
- iOS toolbar > Device Log
Once the tool window is shown, the user can select the physical device from the devices dropdown. When a device is selected, logs will automatically be added to the table. Switching between devices will stop and start the device logging.
In order for the devices to appear in the combobox, an iOS project must be loaded. Additionally for iOS, Visual Studio must be connected to the Mac Server to discover the iOS devices connected to the Mac.
This tool window provides: a table of log entries, a dropdown for device selection, a way to clear log entries, a search box, and play/stop/pause buttons.
Set Debugging Stops
Breakpoints can be set at any point in your application to signal to the debugger to temporarily stop the execution of the program. To set a breakpoint in your Visual Studio, click on the margin area of your editor, next to the line number of the code you wish to break at:
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 will be 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 macOS:
Examine Local Variables
Summary
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.