Building Great Libraries with .NET Standard C h a d G r e e n N e - - PowerPoint PPT Presentation

building great libraries with net standard
SMART_READER_LITE
LIVE PREVIEW

Building Great Libraries with .NET Standard C h a d G r e e n N e - - PowerPoint PPT Presentation

Building Great Libraries with .NET Standard C h a d G r e e n N e b r a s k a . C o d e ( ) A u g u s t 1 5 , 2 0 1 9 @chadgreen Who is Chad Green Director of Software Development at ScholarRx Microsoft MVP (Developer Technology)


slide-1
SLIDE 1

@chadgreen

Building Great Libraries with .NET Standard

C h a d G r e e n N e b r a s k a . C o d e ( ) A u g u s t 1 5 , 2 0 1 9

slide-2
SLIDE 2

@chadgreen

Who is Chad Green

  • Director of Software Development at

ScholarRx

  • Microsoft MVP (Developer Technology)
  • chadgreen@chadgreen.com

 chadgreen.com

  • ChadGreen
  • ChadwickEGreen
slide-3
SLIDE 3

@chadgreen

Agenda

B u i l d i n g G r e a t L i b r a r i e s w i t h . N E T S t a n d a r d

Choosing the Right Version Quick History Lesson

4

When to Use .NET Standard

Referencing .NET Framework Libraries Guidelines for Great Libraries Platform Specific Code

1 3 5 2 1 2 4 3 5 6

slide-4
SLIDE 4

@chadgreen B u i l d i n g G r e a t L i b r a r i e s w i t h . N E T S t a n d a r d

Quick History Lesson

slide-5
SLIDE 5

@chadgreen

Microsoft Development Tools Up to .NET

  • MicroSoft Basic
slide-6
SLIDE 6

@chadgreen

Microsoft Development Tools Up to .NET

  • MicroSoft Basic
  • QuickBASIC
slide-7
SLIDE 7

@chadgreen

Microsoft Development Tools Up to .NET

  • MicroSoft Basic
  • QuickBASIC
  • Visual Basic
slide-8
SLIDE 8

@chadgreen

Introduction of Microsoft .NET

  • Java
  • Managed Runtime
  • Runtime of many names
  • COM+
  • Compound Object Runtime (COR)
  • Universal RunTime (URT)
  • Next-Gen Windows Service (NGWS)
  • .NET
slide-9
SLIDE 9

@chadgreen

Introduction of Microsoft .NET

  • Microsoft actually wanted industry support
  • Took specifications to ECMA
  • ECMA 334 – C# Language Specification
  • ECMA 335 – Common Language Infrastructure (CLI)
  • Microsoft, HP, Intel were core sponsors
slide-10
SLIDE 10

@chadgreen

Microsoft .NET

  • Introduction of CLR
  • Support for object-oriented Web application development
  • Use of DLL class libraries
slide-11
SLIDE 11

@chadgreen

So why something different?

  • .NET – a set of verticals
slide-12
SLIDE 12

@chadgreen

So why something different?

  • .NET – a set of verticals
  • Birth of portable class libraries
slide-13
SLIDE 13

@chadgreen B u i l d i n g G r e a t L i b r a r i e s w i t h . N E T S t a n d a r d

It’s a Whole New World

slide-14
SLIDE 14

@chadgreen

slide-15
SLIDE 15

@chadgreen

It’s a whole new world

.NET Framework .NET Core Xamarin

Windows Only Windows, Linux, Mac OS iOS, Android

slide-16
SLIDE 16

@chadgreen

It’s a whole new world

.NET Framework .NET Core Xamarin .NET Standard

slide-17
SLIDE 17

@chadgreen

What is .NET Standard?

A Specification Defines a set of APIs that all .NET platforms have to implement Not another .NET platform

slide-18
SLIDE 18

@chadgreen

What is .NET Standard?

.NET Core

Xamarin .NET Framework

.NET Standard

slide-19
SLIDE 19

@chadgreen

What is .NET Standard?

.NET Core

Xamarin .NET Framework

Portal Library Portal Library Portal Library

slide-20
SLIDE 20

@chadgreen

What is .NET Standard?

Portable Class Libraries

  • Intersection profile are computed
  • Depend on the targeted platform
  • No systematic versioning approach

.NET Standard

  • Set of APIs that are selected by

humans

  • Independent from any .NET

Platform

  • Versioned linearly and backward

compatible

slide-21
SLIDE 21

@chadgreen

What is .NET Standard?

slide-22
SLIDE 22

@chadgreen

OK, so which framework am I supposed to use?

.NET Framework .NET Core .NET Standard

Windows Only Windows, Linux, Mac OS Cross .NET Platform

slide-23
SLIDE 23

@chadgreen B u i l d i n g G r e a t L i b r a r i e s w i t h . N E T S t a n d a r d

Demo

slide-24
SLIDE 24

@chadgreen B u i l d i n g G r e a t L i b r a r i e s w i t h . N E T S t a n d a r d

Choosing the Right Version

slide-25
SLIDE 25

@chadgreen

Choosing the Right Version

2.1 2.0 1.6 1.5 1.4 1.3 1.2 1.1 1.0

  • A .NET Standard version contains all APIs

from the previous versions

  • A .NET platform implements a specific

.NET Standard version

  • Every .NET Standard version is immutable
slide-26
SLIDE 26

@chadgreen

Choosing the Right Version

A higher version means more APIs, but less platforms A lower version means less APIs, but more platforms Target the lowest possible version

slide-27
SLIDE 27

@chadgreen

Choosing the Right Version

slide-28
SLIDE 28

@chadgreen

Choosing the Right Version

slide-29
SLIDE 29

@chadgreen

Choosing the Right Version

slide-30
SLIDE 30

@chadgreen

Choosing the Right Version

slide-31
SLIDE 31

@chadgreen

Choosing the Right Version

slide-32
SLIDE 32

@chadgreen

Choosing the Right Version

slide-33
SLIDE 33

@chadgreen

Choosing the Right Version

slide-34
SLIDE 34

@chadgreen

Choosing the Right Version

slide-35
SLIDE 35

@chadgreen

Choosing the Right Version

https://dotnet.microsoft.com/platform/dotnet-standard

slide-36
SLIDE 36

@chadgreen

Choosing the Right Version

A higher version means more APIs, but less platforms A lower version means less APIs, but more platforms Target the lowest possible version

slide-37
SLIDE 37

@chadgreen

Choosing the Right Version

.NET Standard 2.1

  • Span<T>
slide-38
SLIDE 38

@chadgreen

Choosing the Right Version

.NET Standard 2.1

  • Span<T>
  • Foundational APIs working with spans
slide-39
SLIDE 39

@chadgreen

Choosing the Right Version

.NET Standard 2.1

  • Span<T>
  • Foundational APIs working with spans
  • Reflection emit
slide-40
SLIDE 40

@chadgreen

Choosing the Right Version

.NET Standard 2.1

  • Span<T>
  • Foundational APIs working with spans
  • Reflection emit
  • SIMD (Single Instruction, Multiple Data)
  • ValueTask and ValueTask<T>
slide-41
SLIDE 41

@chadgreen

Choosing the Right Version

.NET Standard 2.1

  • Span<T>
  • Foundational APIs working with spans
  • Reflection emit
  • SIMD (Single Instruction, Multiple Data)
  • ValueTask and ValueTask<T>
slide-42
SLIDE 42

@chadgreen

Choosing the Right Version

.NET Standard 2.1

  • Span<T>
  • Foundational APIs working with spans
  • Reflection emit
  • SIMD (Single Instruction, Multiple Data)
  • ValueTask and ValueTask<T>
  • DBProviderFactories
slide-43
SLIDE 43

@chadgreen

Choosing the Right Version

.NET Standard 2.1

  • Span<T>
  • Foundational APIs working with spans
  • Reflection emit
  • SIMD (Single Instruction, Multiple Data)
  • ValueTask and ValueTask<T>
  • DBProviderFactories
  • General Goodness
slide-44
SLIDE 44

@chadgreen B u i l d i n g G r e a t L i b r a r i e s w i t h . N E T S t a n d a r d

Referencing .NET Framework Libraries

slide-45
SLIDE 45

@chadgreen

Referencing .NET Framework Libraries

.NET Core Console App .NET Standard Class Library .NET Framework Console App .NET Framework Class Library

.NET Framework Compatibility Shim .NET Portability Analyzer

slide-46
SLIDE 46

@chadgreen B u i l d i n g G r e a t L i b r a r i e s w i t h . N E T S t a n d a r d

When to Use .NET Standard

slide-47
SLIDE 47

@chadgreen

When to Use .NET Standard – New

slide-48
SLIDE 48

@chadgreen

When to Use .NET Standard – Migration

Library is .NET Standard Compatible Need to use it

  • n different

.NET Platforms Already reference it in a .NET Standard class library

slide-49
SLIDE 49

@chadgreen B u i l d i n g G r e a t L i b r a r i e s w i t h . N E T S t a n d a r d

Platform Specific Code

slide-50
SLIDE 50

@chadgreen

Windows Compatibility Pack

  • Microsoft.Windows.Compatibility (NuGet package)
  • Can be referenced from .NET Core as well as .NET

Standard

  • Has ~21k APIs (Windows-only as well as cross-

platform)

  • Contents

ACLs Code Pages Code Dom Configuration Crypto DirectoryServices Drawing EventLog MEF v1 ODBC Perf Counters Permissions Ports Registry Runtime Caching WCF Windows Services

slide-51
SLIDE 51

@chadgreen

Multi-Targeting Best Practices

  • DO start with the .NET Standard 2.0
  • Most general purpose libraries will not need APIs outside this set
  • CONSIDER targeting multiple frameworks
  • If you need to call platform-specific APIs outside of .NET Standard
  • DO NOT drop support for .NET Standard
  • Instead, throw from the implementation and offer capability APIs. This way, your

library can be used anywhere and supports runtime light-up.

  • DO share your component using a NuGet package
  • It shields consumers from having to pick the appropriate implementation
slide-52
SLIDE 52

@chadgreen B u i l d i n g G r e a t L i b r a r i e s w i t h . N E T S t a n d a r d

Guidelines for Great Libraries

slide-53
SLIDE 53

@chadgreen

Versioning

Kind When to increment Comment Package Version Every change The ID of the NuGet package. Assembly Version As you see fit The version number of the

  • assembly. Used by the loader

to resolve assemblies. File Version Every change Generic concept, used by installers to determine which file is newer. Informational Version As you see fit Display string, does not need to be a version.

slide-54
SLIDE 54

@chadgreen

Best Practices

  • DO follow the API Design Guidelines
  • Do target .NET Standard 2.0
  • CONSIDER using multi-targeting to allow for platform-

specific code

  • CONSIDER dual-targeting for .NET Framework 4.6.1
  • DO use NuGet for packaging multi-targeted libraries
  • DO throw PlatformNotSupportedExecption for unsupported APIs
  • DO strong name your libraries
  • AVOID if your library cannot be used on .NET Framework
  • DO check in the public & private key
slide-55
SLIDE 55

@chadgreen B u i l d i n g G r e a t L i b r a r i e s w i t h . N E T S t a n d a r d

Questions

chadgreen@chadgreen.com  chadgreen.com

  • ChadGreen

ChadwickEGreen Slides will be available on my site