Adding Shared Projects Support For Xamarin In Visual Studio 2013
While I love portable class libraries for sharing code across multiple projects, and I absolutely love Shared Projects for sharing code within a single library or project. Shared Projects were introduced with Visual Studio 2013 Update 2 and quickly added to Xamarin Studio enabling you share code easier than ever. The two ways of sharing code are vastly different and you can read about them on the amazing Xamarin documentation, but what you really need to know is that a PCL is an assembly with references and a Shared Project is glorified file linking but contains everything under a project node making it easy to navigate and never having to link a file again. This means that these files are just that….files of code that enable you to do conditional compilation and all that jazz :)
The Problem
The real issue is that when VS 2013 Update 2 shipped it only added Shared Projects if you were creating a Universal App and there was no way to create a separate Shared Project or even easily add one to a non-Universal App. There is no reason for this though as you can “easily” modify the .csproj files to get it working.The Solution
Since manually editing a .csproj is no fun the good people at Microsoft created a Visual Studio extension called the “Shared Project Reference Manager Extension”, which you can find on the Visual Studio Gallery. You can get to this from “Tools -> Extensions & Updates -> Online” and search for Shared Projects:Once you have this installed you can simply do a File->New Project and under C# you will see a shared project!
With your shared project in place simply right click on your “References” of your Xamarin iOS or Android app and you will see a new “Add Shared Reference…” entry in the context menu. After that you are all set and ready to share code. Of course there is nothing special you need to do in Xamarin Studio as it just works out of the box :)
I even have a full video breakdown that you can watch as well: