Configuring Visual Studio 2012 to work with the Xamarin framework and PCLs

If you want to do cross development using Xamarin and Visual studio, you need to install the Xamarin tools for Visual Studio. This will allow you to create solutions that target one or multiple platforms using the magic of MVVM (Model - View - ViewModel) and PCLs (Portable Class Libraries).

The Visual Studio installer can be acquired here.

The download is over 1.2Gb so it may take some time depending on your connection. The installation is fairly quick and painless with only a few steps to follow on the wizard.

Once the installation is complete, you can start working with the new Android and iOS frameworks. One common task is to create a core project which can be shared across multiple platforms. So going through the usual steps you would create a new project:

Portable Class Library Project

Select the name and location and click OK. Then you would be presented with the following screen:

Portable class library framework selection

At this stage, you would realize that there is no option to add either the Android or the iOS frameworks. To resolve this, you have to carry out a few manual steps but nothing too hacky and nowhere near the registry!

Close down Visual Studio and navigate to the following location:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile104\SupportedFrameworks

In this location, you need to create two new files in order to allow Visual Studio to reference the Android and iOS frameworks when creating of PCLs.

First create a new MonoAndroid.xml file. Open and add the following xml content:

<?xml version="1.0" encoding="UTF-8"?> 
<Framework MaximumVersion="*" MinimumVersion="1.6" Profile="*" Identifier="MonoAndroid" DisplayName="Mono for Android"/>

Save and close. Then create a new MonoTouch.xml file. Open and add the following xml content:

<?xml version="1.0" encoding="UTF-8"?>
<Framework MinimumVersion="4.0" MaximumVersion="*" Profile="*" Identifier="MonoTouch" DisplayName="MonoTouch"/>

Save and close. Fire up Visual Studio again and try to create a new PCL project. This time you will be presented with all the applicable frameworks as per below:

PCL4

Now, don't freak out if you see this error above. If you are like me, you may think that something went wrong. However, all is good and the way to resolve this is to change the drop down value from Windows Phone 7 and Higher to Windows Phone 7.5 and Higher like in the screenshot below:

PCL5

If you follow all these steps, you will be able to get your project "off the ground" straight away and without any exceptions.

Happy Coding…


  • Share this post on