intro to cross-platform mobile development · 2019-05-11 · university.xamarin.com intro to...
TRANSCRIPT
![Page 1: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/1.jpg)
Download class materials from
university.xamarin.com
Intro to Cross-Platform
Mobile Development
XAM110
![Page 2: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/2.jpg)
Information in this document is subject to change without notice. The example companies,
organizations, products, people, and events depicted herein are fictitious. No association with
any real company, organization, product, person or event is intended or should be inferred.
Complying with all applicable copyright laws is the responsibility of the user.
Microsoft or Xamarin may have patents, patent applications, trademarked, copyrights, or other
intellectual property rights covering subject matter in this document. Except as expressly
provided in any license agreement from Microsoft or Xamarin, the furnishing of this document
does not give you any license to these patents, trademarks, or other intellectual property.
© 2014-2017 Xamarin Inc., Microsoft. All rights reserved.
Xamarin, MonoTouch, MonoDroid, Xamarin.iOS, Xamarin.Android, Xamarin Studio, and Visual
Studio are either registered trademarks or trademarks of Microsoft in the U.S.A. and/or other
countries.
Other product and company names herein may be the trademarks of their respective owners.
![Page 3: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/3.jpg)
1. Work with shared components
2. Share code using Shared Projects
3. Share code using Portable Class Libraries
4. Share code using .NET Standard libraries
Objectives
![Page 4: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/4.jpg)
Work with Shared Components
![Page 5: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/5.jpg)
1. Add NuGet packages to your
application
2. Add components to your
application
Tasks
![Page 6: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/6.jpg)
❖ One of the main reasons to use
Xamarin is the possibility of sharing
a significant portion of your code
across all your supported platforms
Sharing code
![Page 7: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/7.jpg)
❖ Xamarin applications are
native and therefore will
always include some
platform-specific code
Sharable code
30%
70%
iOS
14%
86%
Android
15%
85%
Windows
statistics taken from iCircuit
Platform
Specific
Cross
Platform
![Page 8: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/8.jpg)
❖ Sharable code is split between
reusable components and
platform-independent code
Sharable code
40%
60%
Your Code
Components
![Page 9: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/9.jpg)
❖ Xamarin.Forms provides shared set of UI controls to design the user
interface that ultimately render native UIs on iOS, Android and Windows
Xamarin.Forms
UI + Application Logic (C#)
(PCL or Shared Project)
Xamarin.Forms
Android iOS Windows
![Page 10: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/10.jpg)
❖ github.com/xamarin/plugins
maintains a list of open-source
components which you can use
in your Xamarin based
applications
Other open-source plug-ins
![Page 11: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/11.jpg)
❖ NuGet is a package manager for .NET that allows you to locate, install,
update and remove shared components from within Visual Studio
NuGet
www.nuget.org
![Page 12: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/12.jpg)
❖ Add NuGet packages in Visual Studio by right-clicking on the project
and selecting Manage NuGet Packages …
Using NuGet in Visual Studio on Windows
Can search, update components and even revert to older revisions
![Page 13: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/13.jpg)
❖ Add NuGet packages in Visual Studio by right-clicking on the project
and selecting Add > Add NuGet Packages…
Using NuGet in Visual Studio for Mac
![Page 14: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/14.jpg)
❖ Anytime you are writing code which does not depend on a specific
platform feature, it is potentially sharable, particularly if it:
What can be shared?
Talks to a web service
Create shared classes + methods and then use them from your platform-specific
code to maximize the shareable surface area
Parses a data
format
Uses a
database
Performs
processing or logic
![Page 15: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/15.jpg)
❖ If the code you are writing depends on device or platform-specific APIs,
or APIs not available in your project, then you will need to isolate it's use
or provide some kind of abstraction to use it from your shared code
When is code not sharable?
Access system
information
Use files and folders
on the device
Access personal
information
Use external
devices
![Page 16: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/16.jpg)
Flash Quiz
![Page 17: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/17.jpg)
① All code you build with Xamarin is sharable across all platforms
a) True
b) False
Flash Quiz
![Page 18: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/18.jpg)
① All code you build with Xamarin is sharable across all platforms
a) True
b) False
Flash Quiz
![Page 19: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/19.jpg)
② The main thing that makes code sharable across platform is _______
a) When it is related to I/O
b) When it comes from NuGet
c) When it does not depend on any platform APIs
d) All of the above
Flash Quiz
![Page 20: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/20.jpg)
② The main thing that makes code sharable across platform is _______
a) When it is related to I/O
b) When it comes from NuGet
c) When it does not depend on any platform APIs
d) All of the above
Flash Quiz
![Page 21: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/21.jpg)
③ Which of the following might be possible candidates for sharing?
a) Code that accesses a web service with HttpClient
b) Validation rules for my UI which uses Regex and returns booleans
c) Code that uses local notifications on the device
d) Code that runs an algorithm to compare flight prices in parallel
Flash Quiz
![Page 22: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/22.jpg)
③ Which of the following might be possible candidates for sharing?
a) Code that accesses a Web Service with HttpClient
b) Validation rules for my UI which uses Regex and returns booleans
c) Code that uses local notifications on the device
d) Code that runs an algorithm to compare flight prices in parallel
Flash Quiz
![Page 23: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/23.jpg)
1. Add NuGet packages to your
application
2. Add components to your
application
Summary
![Page 24: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/24.jpg)
❖ There are two project styles available for sharing code – which one you
select has an impact on how and what kind of code is shared
Available project types
Shared Project Shared Binaries
![Page 25: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/25.jpg)
Share code using
Shared Projects
![Page 26: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/26.jpg)
1. Share code across multiple projects
with a shared project
2. Execute platform-specific code
from a Shared Project
Tasks
![Page 27: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/27.jpg)
❖ Shared Projects enable project-level
sharing of source + assets
✔ single copy of source file
✔ compiled uniquely into project
✔ Normal refactoring + navigation
works
What is a Shared Project?
![Page 28: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/28.jpg)
❖ Shared project defines the included files as well as the build type
(Compile, None, etc.), but does not actually generate any output
Shared Project packaging
Shared.shproj
NoteManager.cs
NoteItem.cs
Paperclip.png
Shared Projects defined
by .shproj type
![Page 29: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/29.jpg)
❖ Adding a reference to a shared project adds all the files to the target
during the compile process, so each source file is compiled for the
target
Shared Project internals
AnyNote.Droid.csproj
NoteFragment.cs
FreehandFragment.cs
AnyNote.iOS.csproj
NoteViewController.cs
FreehandViewController.cs
AnyNote.UWP.csproj
NoteView.xaml.cs
DrawInkView.xaml.cs
![Page 30: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/30.jpg)
Using Shared Projects
Demonstration
![Page 31: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/31.jpg)
❖ Several strategies for managing platform-specific code when using File
Linking or Shared Projects
Platform-specific code strategies
Conditional Compilation
Class Mirroring
Partial Classes + Methods
![Page 32: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/32.jpg)
public static string DatabaseFilePath{
get{
var filename = "HRdb.db3";#if WINDOWS_UWP
var path = filename;#elif __ANDROID__
var path = Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.Personal),filename);
#elif __IOS__string documentsPath = Environment.GetFolderPath(
Environment.SpecialFolder.Personal);var path = Path.Combine(
documentsPath,"..", "Library",filename);
#endifreturn path;
}}
❖ Easiest strategy is to use
conditional compilation to
isolate platform specific
code
#if __MOBILE__
#if __ANDROID__
#if __IOS__
#if WINDOWS_UWP
Conditional compilation
![Page 33: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/33.jpg)
❖ Can provide specific implementation of a dependency used in the shared
project – remember the shared project is not compiled on it's own
Class mirroring
public class NoteManager{
void CloudBackupComplete() {Alert.Show("Success!",
"Notes have been backed up.");}
}Shared Project
class Alert{
internal static void Show(string title,string message) {
new UIAlertView(title, message, null, "OK").Show();
}}
class Alert{
internal static void Show(string title,string message) {
new AlertDialog.Builder(Application.Context).SetTitle(title).SetMessage(message)
}
AnyNote.iOS
AnyNote.Droid
![Page 34: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/34.jpg)
❖ Partial classes allow you to break
your implementation into multiple
source files
❖ Used primarily for generated code
❖ Can also be used to provide
platform-specific implementations
Partial classespartial class NoteManager{
void OnDeleteNote() {if (ShowAlert("Warning!", "...")) {
...}
}}
partial class NoteManager{
bool ShowAlert(string title, string msg) {
...}
}
Shared Project
AnyNote.iOS
![Page 35: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/35.jpg)
❖ Can use partial methods to make
the implementation optional
❖ If the method is not provided by the
implementation, then the call to the
method is omitted from the
compiled code
Partial methods
partial class NoteManager{
partial void ShowPrintSettings();
void PrintNote(NoteItem note) {...ShowPrintSettings();
}}
Shared Project
partial class NoteManager{
// No definition of method}
NoteManager.iOS
![Page 36: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/36.jpg)
Working with Shared Projects
Individual Exercise
![Page 37: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/37.jpg)
Flash Quiz
![Page 38: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/38.jpg)
① Shared Projects create an output assembly directly
a) True
b) False
Flash Quiz
![Page 39: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/39.jpg)
① Shared Projects create an output assembly directly
a) True
b) False
Flash Quiz
![Page 40: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/40.jpg)
② What types of files can you add to a Shared Project?
a) Source Code only
b) Source and Image assets
c) Source and Data files
d) Anything supported by the targets using the project
Flash Quiz
![Page 41: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/41.jpg)
② What types of files can you add to a Shared Project?
a) Source Code only
b) Source and Image assets
c) Source and Data files
d) Anything supported by the targets using the project
Flash Quiz
![Page 42: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/42.jpg)
③ What techniques can be used to isolate platform specific code in a
Shared Project?
a) Conditional Compilation
b) Partial classes
c) Both (a) and (b)
d) None of the above.
Flash Quiz
![Page 43: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/43.jpg)
③ What techniques can be used to isolate platform specific code in a
Shared Project?
a) Conditional Compilation
b) Partial classes
c) Both (a) and (b)
d) None of the above.
Flash Quiz
![Page 44: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/44.jpg)
1. Share code across multiple projects
with a shared project
2. Execute platform-specific code
from a Shared Project
Summary
![Page 45: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/45.jpg)
Share code using
Portable Class Libraries
![Page 46: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/46.jpg)
1. Portable Class Libraries
2. Profiles
3. Handling Platform Abstractions
Tasks
Portable
Class
Library
.NET
Silverlight
Windows
Phone
Android
iOS
UWP
![Page 47: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/47.jpg)
❖ Class Library projects are tied to a
specific platform + frameworks
Class Library projects
![Page 48: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/48.jpg)
❖ Portable Class Libraries are assemblies that can be used by different
flavors of .NET without recompiling
Portable Class Libraries (PCL)
![Page 49: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/49.jpg)
❖ A PCL is tied to a specific profile which defines the specific APIs it can use
How does it work?
Feature.NET
Framework
Windows
StoreSilverlight
Windows
Phone (SL)
Windows
Phone (Store)Xamarin
Core Libraries ✔ ✔ ✔ ✔ ✔ ✔
LINQ ✔ ✔ ✔ ✔ ✔ ✔
IQueryable ✔ ✔ ✔ 7.5+ ✔ ✔
Compression 4.5+ ✔ ✖ ✖ ✔ ✔
Data Annotations 4.0.3+ ✔ ✔ ✖ ✖ ✔
System.IO.File ✖ ✖ ✖ ✖ ✖ ✖
![Page 50: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/50.jpg)
Configuring Portable Class Libraries
You select the platforms the library will be
used on – this decides the profile
The available combinations are controlled
by the profiles Microsoft has defined
The more platforms you choose, the less
APIs you will be able to use
Pick only the framework targets you need right now to give you the broadest API reach
as possible, can always add other targets later if you expand your platforms
![Page 51: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/51.jpg)
❖ Some platform combinations are
not allowed because Microsoft has
not defined a profile for that
combination
❖ IDE will attempt to pick the closest
variation, or give an error and
require that you add an additional
target
Missing profiles
![Page 52: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/52.jpg)
Creating a Portable Class Library
Demonstration
![Page 53: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/53.jpg)
❖ PCLs are limited to features which are common to the targeted frameworks;
this means a lot of classes will be missing when you are in a PCL project
PCL limitations
Selected profile has no constructor on
StreamReader which takes a string
partial class NoteManager{
void LoadNotes(string filename) {var reader = new System.IO.StreamReader(filename);
}}
![Page 54: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/54.jpg)
❖ Several approaches you can take to passing data between the platform-
specific code and the shared (PCL) code
Platform-specific code strategies
Fill in properties
with loaded data
Call the API in the
platform-specific code and
fill in exposed public
properties in the shared
code with the results
![Page 55: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/55.jpg)
❖ Several approaches you can take to passing data between the platform-
specific code and the shared (PCL) code
Platform-specific code strategies
Fill in properties
with loaded data
Open and pass
supported types
to PCL
Decide the location +
filename, open a Streamand let shared code
parse/load the data
![Page 56: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/56.jpg)
Open and pass
supported types
to PCL
❖ Several approaches you can take to passing data between the platform-
specific code and the shared (PCL) code
Platform-specific code strategies
Fill in properties
with loaded data
Design higher-
level abstractionsCan use an abstraction such as
an interface or an event and
provide an implementation of
that abstraction in the
platform-specific project(s)
![Page 57: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/57.jpg)
❖ PCLs can expose events or delegates to request extensibility from the
platform code, particularly effective if requirements are small
Callbacks
public class Dialer {
public static Func<string,bool> MakeCallImpl;
public bool MakeCall(string number) {if (MakeCallImpl(number)) {
...}
}}
Dialer.MakeCallImpl = number =>{return UIApplication
.SharedApplication
.OpenUrl(new NSUrl("tel:" + number));
}
PCL
Xamarin.iOS
![Page 58: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/58.jpg)
❖ Complex requirements can be described by an
abstraction that is defined in the PCL
Platform abstractions
Shared code defines IDialer interface
to represent required functionality – this
is what the PCL uses to get to the API
public interface IDialer{
bool MakeCall(string number);}
PCL
PhoneDialerIOS
PhoneDialerDroid
PhoneDialerWin
Platform projects implement the
shared dialer interface using the
platform-specific APIs
![Page 59: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/59.jpg)
❖ Can supply concrete implementation to PCL via constructor, method or
property setter; this technique is often called Dependency Injection
Injecting dependencies
Dialer.Instance = new Dialer(new iPhoneDialer());
Dialer.Instance.Initialize(new AndroidDialer());
Dialer.Instance.Platform = new WindowsDialer();
OR
OR
![Page 60: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/60.jpg)
Working with Portable Class Libraries
Individual Exercise
![Page 61: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/61.jpg)
Flash Quiz
![Page 62: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/62.jpg)
① Portable Class Libraries share source code files across projects
a) True
b) False
Flash Quiz
![Page 63: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/63.jpg)
① Portable Class Libraries share source code files across projects
a) True
b) False
Flash Quiz
![Page 64: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/64.jpg)
② When you define your platform targets, you are selecting a _______.
a) Configuration
b) Platform Group
c) Profile
d) Grouping
Flash Quiz
![Page 65: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/65.jpg)
② When you define your platform targets, you are selecting a _______.
a) Configuration
b) Platform Group
c) Profile
d) Grouping
Flash Quiz
![Page 66: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/66.jpg)
④ What techniques can I use to add platform-specific code to a PCL?
a) Dependency Injection (DI)
b) Service Locator
c) Publisher / Subscribe (events or messaging system)
d) Any of the above
Flash Quiz
![Page 67: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/67.jpg)
④ What techniques can I use to add platform-specific code to a PCL?
a) Dependency Injection (DI)
b) Service Locator
c) Publisher / Subscribe (events or messaging system)
d) Any of the above
Flash Quiz
![Page 68: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/68.jpg)
1. Portable Class Libraries
2. Profiles
3. Handling Platform Abstractions
Summary
Portable
Class
Library
.NET
Silverlight
Windows
Phone
Android
iOS
UWP
![Page 69: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/69.jpg)
Share code using
.NET Standard libraries
![Page 70: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/70.jpg)
1. Create a .NET Standard library
2. Select a .NET Standard target version
for your library
3. Use a .NET Standard library with a
Xamarin app
Tasks
![Page 71: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/71.jpg)
❖ Sharing code across platforms has some common challenges
Motivation
API surfaces are
not uniform
New platforms may
not have the APIs
your library needs
![Page 72: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/72.jpg)
❖ In .NET, a platform is a set of software components capable of building
and executing an application on some target operating systems
Platforms
.NET Framework(Desktop/Server/Mobile)
Tools Runtime Library
.NET Core(Server/Desktop)
Tools Runtime Library
Mono for Xamarin(Mobile/Desktop)
Tools Runtime Library
The three primary Microsoft platforms let you run apps on a wide range of targets
![Page 73: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/73.jpg)
.NET Framework
Tools Runtime Library
.NET Core
Tools Runtime Library
Mono for Xamarin
Tools Runtime Library
❖ The libraries offered by each platform are different – they do not
provide a uniform API surface for you to code against
Library variation
This makes it difficult for you to write one library that works on all these
platforms – what if you need to use an API that's not available everywhere?
![Page 74: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/74.jpg)
.NET Framework
Tools Runtime
.NET Core
Tools Runtime
Mono for Xamarin
Tools Runtime.NET
Standard
❖ .NET Standard is a library specification that provides the same APIs
across all .NET platforms
What is .NET Standard?
This makes it easier to build a library that works on all these platforms
since the available APIs are standardized
.NET
Standard
.NET
Standard
![Page 75: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/75.jpg)
❖ .NET Standard is under active development and has many versions –
each new version increases the number of available APIs
.NET Standard versions
2.0 (Q3 2017)
1.6
...
1.1
1.0
New versions are
supersets, they
do not remove
any existing APIs
![Page 76: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/76.jpg)
❖ Visual Studio 2017 and Visual Studio for Mac v7.0 include a project
template for creating .NET Standard class libraries
How to create a .NET Standard library?
Choose the version in the properties2Use the template to create the project1
![Page 77: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/77.jpg)
❖ The .NET team at Microsoft decides which APIs to add to each .NET
Standard release (this includes a public feedback process)
Available APIs
Version APIs API count
1.0 Primitives, reflection, tasks, collections, LINQ to Objects, XML, ... 7,949
1.1 Concurrent collections, interop, HTTP interactions, ... 10,239
1.2 Threading timer, more interop, ... 10,285
1.3 Console, file system, thread pool, sockets, cryptography, ... 13,122
1.4 More cryptography, ... 13,140
1.5 More assembly members, more streams, ... 13,355
1.6 Even more cryptography, more regex, expression compiling, ... 13,501
2.0 (Q3 2017)Data classes, drawing, pipes, caching, SMTP, web sockets, more
serialization, XPath, expanded many existing classes, …32,638
![Page 78: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/78.jpg)
.NET Standard API use
❖ Your library can use .NET Standard APIs added in versions less than or
equal to your target version
.NET Standard
v1.0 APIs.NET Standard
v1.1 APIs.NET Standard
v1.2 APIs.NET Standard
v1.3 APIs.NET Standard
v1.4 APIs.NET Standard
v1.5 APIs.NET Standard
v1.6 APIs
My .NET Standard libTarget framework:
.NETStandard 1.4 ˅
![Page 79: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/79.jpg)
Create a .NET Standard library and use .NET Standard APIs
Demonstration
![Page 80: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/80.jpg)
.NET Framework v4.6.2
Tools Runtime v1.5
.NET Core v1.0
Tools Runtime v1.6
Xamarin Cycle 9
Tools Runtime v1.6
❖ Each platform can support its preferred version of .NET Standard
Platform support
![Page 81: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/81.jpg)
❖ Your library can be used by platforms supporting your targeted .NET
Standard version or higher
Where can your library be used?
.NET Framework v4.5.1
Tools Runtime v1.2
.NET Core v1.0
Tools Runtime v1.6
Xamarin Cycle 9
Tools Runtime v1.6
My .NET Standard libTarget framework:
.NETStandard 1.4 ˅
![Page 82: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/82.jpg)
Which libraries can you reference?
❖ A library targeting .NET Standard can reference a library targeting the
same .NET Standard version or lower
Library DTarget framework:
.NETStandard 1.6 ˅Library B
Target framework:
.NETStandard 1.1 ˅Library C
Target framework:
.NETStandard 1.4 ˅
Library ATarget framework:
.NETStandard 1.4 ˅
![Page 83: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/83.jpg)
How to choose target version
❖ You should target the lowest .NET Standard version that gives you all the
APIs you need – this maximizes the number of platforms you can run on
My LibraryTarget framework:
.NETStandard 1.6 ˅My Library
Target framework:
.NETStandard 1.2 ˅
Which target version
should you choose?
Targeting higher means
you can use more APIs
(e.g. any APIs added
in 1.0 through 1.6)
Targeting lower means you
are compatible with more
platforms (e.g. all that
support at least 1.2)
![Page 84: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/84.jpg)
PCL Profile compatibility
❖ Most PCL Profiles popular in Xamarin development are paired with .NET
Standard versions, allowing those libraries to reference each other
PCL Profile (all support Xamarin) .NET Standard
Profile151 (.NET Framework 4.5.1, Windows 8.1, Windows Phone 8.1) 1.2
Profile44 (.NET Framework 4.5.1, Windows 8.1) 1.2
Profile111 (.NET Framework 4.5, Windows 8, Windows Phone 8.1) 1.1
Profile7 (.NET Framework 4.5, Windows 8) 1.1
Profile259 (.NET Framework 4.5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8) 1.0
Profile78 (.NET Framework 4.5, Windows 8, Windows Phone Silverlight 8) 1.0
![Page 85: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/85.jpg)
❖ Visual Studio lets you convert a PCL to a .NET Standard library
Convert a PCL to .NET Standard
Choose your version2Retarget in the project properties1
![Page 86: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/86.jpg)
Handle platform differences
❖ You use the same techniques to handle platform-specific code in .NET
Standard libraries as in PCLs
CallbacksInterface
Abstractions
Dependency
Injection
![Page 87: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/87.jpg)
Upgrading from PCL to .NET Standard Libraries
Demonstration
![Page 88: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/88.jpg)
Flash Quiz
![Page 89: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/89.jpg)
① Libraries targeting .NET Standard versions share source code files across
projects
a) True
b) False
Flash Quiz
![Page 90: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/90.jpg)
① Libraries targeting .NET Standard versions share source code files across
projects
a) True
b) False
Flash Quiz
![Page 91: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/91.jpg)
② A .NET Standard library targeting .NET Standard version 1.4 can use
APIs from .NET Standard 1.2
a) True
b) False
Flash Quiz
![Page 92: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/92.jpg)
② A .NET Standard library targeting .NET Standard version 1.4 can use
APIs from .NET Standard 1.2
a) True
b) False
Flash Quiz
![Page 93: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/93.jpg)
1. Create a .NET Standard library
2. Select a .NET Standard target version
for your library
3. Use a .NET Standard library with a
Xamarin app
Summary
![Page 94: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/94.jpg)
Code-sharing comparison
❖ Selecting a code-sharing technique depends on many factors – each
style has advantages and disadvantages
Shared Projects PCL / .NET Standard libraries
Pros Cons Pros Cons
All APIs available Can lead to spaghetti code Enforces architectural design Limited APIs available
Platform-specific logic
can be added directly
Difficult to unit test due to
conditional code
Can be unit tested
separately
Difficult to share non-
code files
All file types can be
shared
Must be shipped in source
form
Can be shipped in binary
form (NuGet)
Limited to target
platforms or APIs
Smaller package
sizes/platform-
specific optimizations
Requires more work to
integrate platform-
specific code
![Page 95: Intro to Cross-Platform Mobile Development · 2019-05-11 · university.xamarin.com Intro to Cross-Platform Mobile Development XAM110. Information in this document is subject to change](https://reader030.vdocuments.mx/reader030/viewer/2022041015/5ec6e82248459401b9566bdf/html5/thumbnails/95.jpg)
Thank You!
Please complete the class survey in your profile:
university.xamarin.com/profile