Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class libraries in VS 2015 - Building Cross Platform Libraries

There are different class libraries I can create in VS 2015 with Xamarin installed:

  1. Class Library
  2. Class Library (Android)
  3. Class Library (Package)
  4. Class Library (Portable for Universal Apps)
  5. Class Library (Portable)
  6. Class Library (Xamarin.Forms)

I would love to know the difference between each - just a brief would do :)

The Scenario

Our team is currently developing a new project which we are targeting for multiple platforms - web and mobile (Xamarin) primarily. While we decided to focus on the MVC web app first, we want to create a single project to contain all models and business classes (logic) so that it can be used across our projects later on. Which class library would be the most appropriate?

like image 225
kent-id Avatar asked Sep 28 '15 00:09

kent-id


1 Answers

This question has a pretty large scope, I'll try answer as best I can:

Class Library

A standard .NET class library which outputs a DLL. This project type can only be used on Desktop platforms (Mac, Windows). These project types cannot be referenced by Android and IOS projects.

Class Library (Android)

An Android specific class library similiar to a normal Android library. This project is designed to share Android-specific resources such as activities, fragments, views, drawables, strings etc. This project can only be referenced by Android App projects or other Android library projects.

We've typically put our main Android app into a library then done a splash screen only Android Application that links the library project. This is so we can isolate each screen into a seperate "Testbed" application to test each screen independently without needing to go through the entire app to test them.

Class Library (Package)

This type isn't in my VS install so I can't comment on what it is.

Class Library (Portable for Universal Apps)

A Portable Class Library that targets .NET 4.5 including support for Windows 8, Xamarin.Android, Xamarin.iOS and Xamarin.iOS (classic). This is TargetFrameworkProfile Profile7.

Class Library (Portable)

A Portable Class Library that targets .NET 4.5 with support for Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8, Xamarin.Android, Xamarin.iOS and Xamarin.iOS (classic). This is TargetFrameworkProfile Profile259.

Class Library (Xamarin.Forms)

A Portable Class Library that targets .NET 4.5 with support for Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8, Xamarin.Android, Xamarin.iOS (classic), Xamarin.iOS Unified and Xamarin.Mac Unified. This is TargetFrameworkProfile Profile78.

Note that the libraries Portable for Universal Apps, Xamarin.Forms and Portable are identical project types (a PCL library) except Xamarin.Forms includes support for the greatest number of platforms.


In terms of project structure, we have a project for each platform (Android, iOs, Windows) that references a PCL (that defines our interfaces and DB entities) and a shared project that implements the majority of the application logic.

I suggest reading the following links and using the Tasky source code as a basis for your application:

  • Building Cross Platform Applications
  • Shared Projects
like image 79
matthewrdev Avatar answered Oct 28 '22 08:10

matthewrdev