Upload
falafelsoftware
View
362
Download
0
Embed Size (px)
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!
Citation preview
Share More Code on !iOS, Android, & Windows!w/ Portable Class Libraries!
James Montemagno!Developer Evangelist, Xamarin!@JamesMontemagno!
How to reach all platforms What are PCLs How do we create them How do we share them
Agenda!
How to reach all platforms What are PCLs How do we create them How do we share them
iOS and Android in C#? How can this be!
Xamarin’s Unique Approach!
Native With !Code Sharing!
Windows APIs!
iOS APIs | 100% Coverage!
Android APIs | 100% Coverage!
C# Runs on 2.5+ Billion Devices!!
How do we share code?
File Linking == “Fun”!
Linking files is HORRIBLE
Shared Projects! • Drop dead simple
code sharing • Glorified File Linking • Allows Compiler
Directives in Code • Best for “Inner” app
sharing
Sharing Code Should Be Easy
How to reach all platforms What are PCLs How do we create them How do we share them
• 1 Assembly • Multiple Platforms • Including: • Android • iOS
Portable Class Libraries!
What can you use?!
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?!
• Centralized Code Sharing • How you expect it to work • Debug seamlessly into and out of PCL
• Project/Assembly Sharing • NuGet
Benefits!
• 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!
What is out there?
• 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!
• Easier to use • Easier to create • True Cross Platform
Portable Class Libraries
Available to Everyone!!
• 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!
Well Documented!
How to reach all platforms What are PCLs How do we create them How do we share them
2 Ways to Create Standard PCL Advanced PCL
• Reference Assembly • API Contract
• Implementation
2 Parts to a PCL!
Standard - PCL Profile Only!
Limited to PCL Subset Easy to manage Easy to share
Demo
• Reference Assembly • API Contract
• Implementation
2 Parts to a PCL!
Advanced - Bait and Switch!
Tap into platform specific code Your users never know! Pure compilation magic ;)﴿
Demo
Why this works!• If we match • Assembly Name • Version • Class Structure
• PCL binary is replaced with platform binary
How to reach all platforms What are PCLs How do we create them How do we share them
• NuSpec • NuPackage
2 Parts "!
Demo
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?!
• Getting Started with PCL • http://bit.ly/pcl-‐get-‐started
• Bait and Switch • http://log.paulbetts.org/the-‐bait-‐and-‐
switch-‐pcl-‐trick/
Resources!
Get Started Today: xamarin.com/download"
Q & A!!Get your free C# t-shirt:!xamarin.com/shirt!
Find Me:!@JamesMontemagno | @XamarinHQ!http://motzcod.es | http://blog.xamarin.com!