A mobile device is the computer for many people — look around and watch kids tweet and grandparents update their Facebook status. Apple seemingly established the mobile market with its iPhone, but the Android platform has burst on the scene and taken over market share.
Xamarin’s history and pricing
Xamarin has been on the .NET scene for a few years, though it got its start more than a decade ago with the open source Mono project. Over the years, Mono has changed hands, with it finally finding a home as the core of the Xamarin product line. Mono is still open source and freely available, but Xamarin with Visual Studio support is not.
You can use Xamarin Studio for free, but Visual Studio support starts with the Business Edition (currently $999/year); its store provides all of the information. There is free training and discounts for MSDN subscribers. It will be interesting to see how Xamarin is offered if Microsoft ever decides to purchase the company.
Up and running
A 30-day trial version is available for download from the Xamarin site. The following components are installed with Xamarin:
- Xamarin.iOS allows you to build native iOS applications.
- Xamarin.Android allows you to build native Android applications.
- Xamarin.Mac allows you to build OS X applications in C#.
- Xamarin.Studio is the standalone Xamarin IDE. Figure A shows it opened with the New Solution option selected. The marriage with Microsoft continues, as the latest version of the Xamarin IDE includes NuGet support.
- Visual Studio integration: A Visual Studio add-in is installed to facilitate Xamarin project development within the Visual Studio IDE. Figure B shows the new Xamarin-centric applications available once it is installed.
- SDK: The necessary SDKs are installed for Android, Apple, and Java.
The standalone Xamarin IDE can be used without Visual Studio.
Xamarin includes new mobile Visual Studio project types.
With Xamarin installed, you are a step closer to building Android and/or iOS applications with C# via Visual Studio. You will need a Xamarin account to build and run these projects in Visual Studio. You will be presented with the window shown in Figure C when you try to execute code. It’s free to sign up.
Once signup is complete (or you sign in using an existing account), you are presented with the window in Figure D to decide if you want to purchase the product or do a trial. Your Xamarin account options are available in Visual Studio (as shown in Figure E), so settings can be changed after initial configuration.
You must create an account with Xamarin to fully utilize the Visual Studio options.
Once you sign up with Xamarin, you must choose to do a trial or pay for the product.
Xamarin account settings are available via the Tools menu in Visual Studio.
Test driving Xamarin
The sample solutions available on the Xamarin site are a good place to start learning how to use the platform. I chose the Xamarin Store application, which is available in a zip file (also, you can get a free t-shirt if you run the application). Once downloaded, you can open within Xamarin and poke around the code to see how it can be organized. Figure F shows the solution opened in Visual Studio 2013 Ultimate.
The solution shown in Figure F demonstrates one of the key features of using Xamarin: a common or shared code base with specific code for each platform. The solution uses shared data classes (Color.cs, FileCache.cs, etc.) along with share Helper and Model classes. While you still have to build specific native code for target platforms, the ability to share some code will reduce maintenance and hopefully development. The full details of the code and building an application is beyond this article, but Figure G does show one of the Android emulators (there is one for each platform version) launched from Visual Studio — an easy to use approach to testing an application.
Browsing the sample Xamarin Store application in Visual Studio.
Android emulator launched from Visual Studio.
I had heard and read a lot of good things about Xamarin, so I was happy to finally get to use it. The installation process takes a long time, but then again, the installs of the last two Visual Studio versions have been time-consuming. I set it up on Windows 7 and Windows 8.1 machines. Both environments were sluggish (Visual Studio always seems to take some time to launch). I did not see additional problems in Windows 8.1, but the Windows 7 environment repeatedly crashed when trying to work with source code.
Given the problems with Windows 7, I ended up sticking with Windows 8.1. The ancillary tools (SDKs and emulators) were problem free. One caveat with developing for iOS (and Mac) is the availability of a Mac computer to build and host the iOS solution; this requires additional setup on the Mac machine (XCode and Xamarin installation/configuration), which was not difficult, but it does mean you need an additional machine.
Will Xamarin be standard for Microsoft?
I knew there were changes on the horizon with Xamarin’s large presence at TechEd 2013. A partnership between Microsoft and Xamarin was announced in late 2013, so I don’t think anyone will be surprised if Microsoft eventually purchases Xamarin.
The integration with Visual Studio is great, as it allows developers to continue with an environment in which they are comfortable, so they can focus on learning the ins and outs of mobile development without worrying about a new IDE. It looks like it is going to be the standard for mobile development with Microsoft tools.