+ All Categories
Home > Software > Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno |...

Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno |...

Date post: 02-Jul-2015
Category:
Upload: falafelsoftware
View: 361 times
Download: 0 times
Share this document with a friend
Description:
Microsoft’s Portable Class Libraries(PCL) have become an extremely popular way to create true cross platform libraries, that even run on platforms like Android and iOS. PCLs allow you to write all of your logic in one project and compile to one library and then add it to any targeted platforms. As a subset of the .NET framework there are important design and implementation decisions to take into consideration when building and using PCLs. This session will show you how to get the most out of PCL projects, including strategies for structuring cross-platform solutions, and tips for using PCLs to replace your favorite missing .NET features. Take code reuse to the next level with PCLs and Xamarin in your Android, iOS, Windows Phone, and Windows Store apps. In this session you will learn what Portable Class Libraries are and if you should use Portable Class Libraries by learning the positives and negatives that come along with PCLs. I will walk through getting started creating truly reusable Portable Class Library targeting Xamarin.Android, Xamarin.iOS, Windows Phone, and Windows Store. We we will add new features by writing code once in your PCL and have it available for use on all platforms in C# or VB.NET!
45
Share More Code on iOS, Android, & Windows w/ Portable Class Libraries James Montemagno Developer Evangelist, Xamarin @JamesMontemagno
Transcript
Page 1: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Share More Code on !iOS, Android, & Windows!w/ Portable Class Libraries!

James Montemagno!Developer Evangelist, Xamarin!@JamesMontemagno!

Page 2: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

How to reach all platforms What are PCLs How do we create them How do we share them

Agenda!

Page 3: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

How to reach all platforms What are PCLs How do we create them How do we share them

Page 4: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

iOS and Android in C#? How can this be!

Page 5: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Xamarin’s Unique Approach!

Native With !Code Sharing!

Page 6: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Windows APIs!

Page 7: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

iOS APIs | 100% Coverage!

Page 8: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Android APIs | 100% Coverage!

Page 9: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

C# Runs on 2.5+ Billion Devices!!

Page 10: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

How do we share code?

Page 11: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

File Linking == “Fun”!

Page 12: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Linking files is HORRIBLE

Page 13: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Shared Projects! •  Drop dead simple

code sharing •  Glorified File Linking •  Allows Compiler

Directives in Code •  Best for “Inner” app

sharing

Page 14: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Sharing Code Should Be Easy

Page 15: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

How to reach all platforms What are PCLs How do we create them How do we share them

Page 16: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

•  1 Assembly •  Multiple Platforms •  Including: •  Android •  iOS

Portable Class Libraries!

Page 17: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

What can you use?!

Page 18: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

It’s complicated

DO NOT READ THIS Portable class libraries are made up of two concepts: an API contract (﴾AKA: reference assembly)﴿ and an implementation. Most of the time, those concepts exist together in a single assembly. PCLs, however, have the flexibility to have multiple implementations for a single API contact. This 2nd case is useful, when implementations need to be platform-‐specific in some way (﴾ex: X86 vs. ARM or Android vs. iOS)﴿. In this case, a PCL would have a single reference assembly that consumers compile with, and then implementations available to be deployed for each of the supported platforms. In all cases, PCLs expose a surface area that is compatible with multiple .NET platforms.

What is a PCL?!

Page 19: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

•  Centralized Code Sharing • How you expect it to work • Debug seamlessly into and out of PCL

•  Project/Assembly Sharing •  NuGet

Benefits!

Page 20: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

•  Platform-‐specific libraries can’t be referenced •  E.g. No Silverlight Control Toolkit •  No P/Invoke to C/C++

•  PCL is a subset of .NET

Platform Independent APIs!

Page 21: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

What is out there?

Page 22: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

•  Async for .NET Framework 4, Silverlight 4 and 5, and WP 7.5 & 8 •  Microsoft BCL Build Components •  Microsoft BCL Portability Pack •  Microsoft Composition •  Microsoft Compression •  Microsoft HTTP Client Libraries •  Microsoft Immutable Collections •  Microsoft ASP.NET SignalR .NET Client •  ODataLib

Microsoft NuGet PCLs!

Page 23: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

•  Easier to use •  Easier to create •  True Cross Platform

Portable Class Libraries

Available to Everyone!!

Page 24: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

•  Xamarin.Forms •  MvvmCross •  ReactiveUI •  Akavache – Async Persistent Key-‐Value Store •  Splat – Image Loading •  Budgie – Twitter Library •  Azure Mobile Services •  Json.Net

•  SO MANY MORE!!!

Awesome Portable Class Libraries!

Page 25: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Well Documented!

Page 26: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

How to reach all platforms What are PCLs How do we create them How do we share them

Page 27: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

2 Ways to Create Standard PCL Advanced PCL

Page 28: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

•  Reference Assembly • API Contract

•  Implementation

2 Parts to a PCL!

Page 29: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Standard - PCL Profile Only!

Limited to PCL Subset Easy to manage Easy to share

Page 30: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014
Page 31: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Demo

Page 32: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

•  Reference Assembly • API Contract

•  Implementation

2 Parts to a PCL!

Page 33: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Advanced - Bait and Switch!

Tap into platform specific code Your users never know! Pure compilation magic ;)﴿

Page 34: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014
Page 35: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Demo

Page 36: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Why this works!•  If we match •  Assembly Name •  Version •  Class Structure

•  PCL binary is replaced with platform binary

Page 37: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

How to reach all platforms What are PCLs How do we create them How do we share them

Page 38: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014
Page 39: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

•  NuSpec •  NuPackage

2 Parts "!

Page 40: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Demo

Page 41: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

You can read this now Portable class libraries are made up of two concepts: an API contract (﴾AKA: reference assembly)﴿ and an implementation. Most of the time, those concepts exist together in a single assembly. PCLs, however, have the flexibility to have multiple implementations for a single API contact. This 2nd case is useful, when implementations need to be platform-‐specific in some way (﴾ex: X86 vs. ARM or Android vs. iOS)﴿. In this case, a PCL would have a single reference assembly that consumers compile with, and then implementations available to be deployed for each of the supported platforms. In all cases, PCLs expose a surface area that is compatible with multiple .NET platforms.

What is a PCL?!

Page 42: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

•  Getting Started with PCL • http://bit.ly/pcl-‐get-‐started

•  Bait and Switch • http://log.paulbetts.org/the-‐bait-‐and-‐

switch-‐pcl-‐trick/

Resources!

Page 43: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Get Started Today: xamarin.com/download"

Page 44: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Q & A!!Get your free C# t-shirt:!xamarin.com/shirt!

Find Me:!@JamesMontemagno | @XamarinHQ!http://motzcod.es | http://blog.xamarin.com!

Page 45: Share More Code on iOS, Android, and Windows with Portable Class Libraries - James Montemagno | FalafelCON 2014

Recommended