I had a discussion with a developer who was getting into .Net development and had questions in regards to the many ways we can reuse code across platforms. We have several ways of reusing code, all with pro’s and con’s. I tried to just quickly summarize what we can and cannot do, and what the rough recommendations are. Feel free to correct me if I’m wrong, or if something is missing in the matrix.
I’ve left out dealing with platform differences as preferred way (be that abstraction of conditional compilation) is a matter of taste.
One could question if it makes sense to compare linked files and shared project, but I’ve left them as two separate options as they have two distinct different ways of setting up the sharing. Shared project works by linking files, but does the ‘heavy lifting’ for us- which is quite valuable and allows for future improvements such as extended tooling and authoring support beyond what we got in the latest Visual Studio release.
Coming later this week
* You could share with other XAML tech based applications but with such restrictions it would most likely not be worth it, in my opinion.
** API access will be limited to the most limited platform targeted
*** Brokered components can call native APIS, but this is for Windows Store Apps only, and only if they are side loaded!
Rough recommendations (as reflected by documentation and developers using these technologies):
If only very few files are shared and for some reason you don’t want to create a Shared project to hold those files
When targeting several platforms (such as iOS and Android) for scoping reusable data objects, services and other API independent logic. Or when you need just one binary. Can be used with linked files / Shared project. API access will be limited to the most limited platform targeted.
When cross language is needed, or you want to call native APIs (for side loaded Windows Store Apps only).
Shared project (Universal Apps)
Best option for Windows Store and Windows Phone (and xBox later) targeting. Can be used for other project types and platforms and in combination with the other sharing options.
Sharing views using PCL: