Details and Example
Assume we are building a cross-platform library called “XamUtils” to be used on 3 platforms: iOS, Android, and Windows Phone.
Solution Layout:
The solution will contain 6 projects, as follows:
- Project Name: XamUtils
- Project Type: PCL (“Cross Platform: Library: Portable Library”)
- Holds very little code; exists mainly for reference by PCL client projects such as Xamarin.Forms PCL projects
- Has references to the “XamUtils.Abstrations” and the “XamUtils.Shared” projects
- Contains stub implementations of all classes and methods that are implemented in the platform-specific projects.
- Project Name: XamUtils.Abstractions
- Project Type: PCL
- Holds interfaces and enums used by all code
- Has no references to any other projects
- Project Name: XamUtils.Shared
- Project Type: “Shared Project” (“Cross Platform: Library: Shared Project”)
- Holds all common or shared code.
- (Because this is a shared project, there are no references to anything else)
- Project Name: XamUtils.iOS
- Project Type: “iOS Library”
- Holds the implementation code for any platform-specific code for the iOS platform
- Has references to the “XamUtils.Abstrations” and the “XamUtils.Shared” projects
- Project Name: XamUtils.Android
- Project Type: “Android Library”
- Holds the implementation code for any platform-specific code for the Android platform
- Has references to the “XamUtils.Abstrations” and the “XamUtils.Shared” projects
- Project Name: XamUtils.WinPhone
- (Same pattern as for XamUtils.iOS and XamUtils.Android)
What you actually end up building are 5 DLL’s:
- XamUtils.Abstractions.dll – Contains interfaces and enums; is referenced by everything else
- XamUtils.dll, the PCL version – Included in the PCL portion of PCL-based applications
- XamUtils.dll, the iOS version – Included in iOS-specific applications
- XamUtils.dll, the Android version – Included in Android-specific applications
- XamUtils.dll, the WinPhone version – Included in WinPhone-specific applications
Anything in the “Shared” project gets compiled into each of the “XamUtils.dll” variations.