Xamarin Shared and PCL Projects – A Comparison

Developers have always had problems supporting multiple platforms in application development, mainly because even though a lot of the code was repetitive, there wasn’t many options available for code sharing. What would often happen is that developers (say wanting to support classes for an ASP.NET web site and a Windows Phone Library application) would write the code for one project and then link the file to the other project. This solved the problem, but adds the extra step of adding the files (plus potential synchonization issues if you forget to add the file). Microsoft offered up Project Linker, a free tool that linked code in projects together. This did work, and solved some of these problems. You were dependent on an external tool for that ability.

A while back, portable class library (PCL) support was added, which addressed this very need: provide the ability to create a project that can be shared across all of these different platforms. This works create to write common code like interfaces, DTO’s, and utility classes, but doesn’t necessarily cover platform-specific features.

When it comes to sharing code, PCL’s don’t quite stretch into the mobile arena, which is where Xamarin comes into play. Since it uses C#, Xamarin supports portable class library (PCL) projects in Visual Studio, and have recently added support within Xamarin Studio. But they also have provided another feature to address code sharing: shared projects. Xamarin documented how shared projects work with great detail. Essentially a shared project works by copying its code into any project that references it. If you have an iOS, Android, or Windows Phone app, the code is copied to each of the projects that refer to it, and thus this shared code is pushed into (similar to how Project Linker works) the dependent projects. This is yet another way that project sharing can work within Xamarin.

Code-sharing probably provides a little more capability than PCL; PCL only contains a subset of assemblies it can refer to, and thus the sharing feature provides you with a little more capability, at the reduced cost of needing separate projects to compile the code into (although, you probably have a project setup for each environment anyway). The Sharing feature is just another tool available to developers to create great applications.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s