Associating a Visual Studio 2013 “Shared” Project with your Xamarin Projects

The new Visual Studio 2013 Update RC2 brings with it the concept of “Universal Apps,” where a developer can have multiple platform targets all importing the same project full of code that is shared among them. This keeps you from having to build a Portable Class Library in situations where you don’t need (or want) the code to be usable by third parties.

When I tried to use one of these Shared projects in my Xamarin.iOS and Xamarin.Android code, things got a little dicey. There doesn’t seem to be any way in the IDE to make the connection right now.

A quick trick with the XML project files was able to get it working. Simply add the appropriate import tag to the project file for your iOS or Android project, reload it in the IDE and it’ll pick up the reference (complete with the fun new ‘Shared Project’ icon.)

The tag to add can go right before the closing tag at the bottom of the project. You’ll need to add a Universal Project to your solution to get the shared project type, so do that first. Then, open the .CSPROJ file for either the Windows 8.1 or Windows Phone 8.1 target and look for the import line that references the shared code. In my case, it looked like this:

<Import Project="..\HubApp1.Shared\HubApp1.Shared.projitems" Label="Shared" />

Simply copy that and paste it into the project file for your iOS or Android target, in roughly the same place, then re-open the solution in VS2013.

The shared project successfully referenced in my HelloWorld1 project, which is a Xamarin.iOS application.

If you see it complain about a missing project, you might need to double-check the relative path in the Import tag.

I can now reference code from the Shared project in my iOS project.

I’m sure Xamarin are rolling out official support for this, and there might be an easier way to do this, but for now this got me where I needed to go. Hope it helps you, too!