2. Swaminathan Vetri
Lead Engineer @ JCPenney
Microsoft MVP - Visual Studio &
Development technologies
Windows/Web/Cross platform mobile
developer
Blogger, Speaker, Amateur
photographer, Gadget freak
@svswaminathan Wannabeegeek.com 2
3. Agenda
• What is .Net Standard ?
• Why .Net Standard ?
• .Net standard vs PCL
• Porting existing libraries to .Net Standard
• Demos
• Creating a new .netstandard library
• Consuming .netstandard library in various .net implementations
• Porting existing libraries to .netstandard library
3
4. What is .NET Standard?
• .NET Standard is a specification
• A set of APIs that all .NET platforms have to implement
.NET Standard
.NET Framework
.NET Core
Xamarin
~
~
HTML specification
Browsers
4
7. .NET today—reusing code
Difficult to reuse skills
• Need to master 3+1 base class libraries
Difficult to reuse code
• Need to target a fairly small common
denominator
Difficult to innovate
• Need implementations on each platform
7
9. .NET tomorrow
.NET Standard
Reuse skills
• Master one BCL, not a Venn diagram
Reuse code
• Common denominator is much bigger
Faster innovation
• Target .NET Standard & run anywhere
9
10. Difference to Portable Class Libraries (PCL)
• PCLs were an after thought, i.e. each platform could decide which
APIs to includes
• No systematic approach to versioning
• Computed intersection profiles
• Each PCLs is targeting a specific set of
platforms
• Not compatible with newer platforms
• Hard to understand compatibility relationships
Platform 3Platform 1
Platform 2
Intersection
Profiles 10
11. 2.0
1.6
1.3
Versioning in .NET Standard
• Higher versions incorporate all
APIs from previous versions.
• Projects targeting version X.Y can
reference libraries & projects
targeting any version between 1.0
and X.Y
• Concrete .NET platforms
implement a specific version of
.NET Standard
• From that platform you can
reference libraries up to that version
1.0
11
12. What version should you target?
• The higher the version, the more APIs you have
• The lower the version, the more platforms support it
Lower Version
More Reach
Higher Version
More APIs
12
15. • .NET Standard is represented by
• The NuGet package NetStandard.Library which contains the reference
assembly netstandard.dll
• At build time
• .NET Standard bridges references to existing .NET Framework and PCL
assemblies via type forwarding
• At runtime
• Each platform provides an implementation for netstandard.dll that
type forwards to its implementation
How does .NET Standard work?
15
16. What can you reference from .NET
Standard?
My Standard Library 2.x
.NET Standard Library .NET Framework LibraryPortable Class Library
.NET FRAMEWORK .NET CORE XAMARIN
Via Portability
Via Compatibility Shim
Legend
Application Type
Is able to reference
16
17. .NET Standard under the hood
TYPE
FORWARDING
This happens when you build a .NET Standard-based Library
17
18. .NET Standard under the hood
TYPE
FORWARDING
This happens when you load .NET Standard-based library
18
19. • .NET Standard (mostly) only contains APIs that will work everywhere
• We generally avoid adding large chunks of APIs that don’t work everywhere
• A small set of APIs will throw PlatformNotSupportedException
• Platform specific APIs sit on top of .NET Standard & you can add
references to them
• Examples: Registry, Reflection Emit, Access Control, Windows Identity
• You’ll become less portable
Platform specific APIs & .NET Standard
19
20. Platform specific APIs & .NET Standard
TYPE
FORWARDING
This happens when you build a .NET Standard-based library with platform-specific extensions
TYPE
FORWARDING
20
21. Platform specific APIs & .NET Standard
This happens when you load .NET Standard-based library with platform-specific extensions
EXCEPTION
TYPE
FORWARDING
21
23. Porting Existing libraries
• APIPORT.exe – API porting analyzer to check what percentage of
existing DLLs are compatibility
• .Net Portability analyzer – Visual Studio Extension to analyze the
source code for compatibility
• Tools to check the .NET API availability/compatibility
• http://apisof.net
• http://icanhasdot.net
• API Analyzer – to check the cross platform compatibility of APIs
23
Notes: Even if we are reusing a lot across components (especially with the open sourcing last year), the reality is that each platform has its own implementation of the base libraries.
Note: .NET Framework BCL and Mono BCL are the same APIs, different implementation. .NET Core “Core Library” is a similar set of APIs, but different.
Notes: Even if we are reusing a lot across components (especially with the open sourcing last year), the reality is that each platform has its own implementation of the base libraries.
Note: .NET Framework BCL and Mono BCL are the same APIs, different implementation. .NET Core “Core Library” is a similar set of APIs, but different.
Notes: Even if we are reusing a lot across components (especially with the open sourcing last year), the reality is that each platform has its own implementation of the base libraries.
Note: .NET Framework BCL and Mono BCL are the same APIs, different implementation. .NET Core “Core Library” is a similar set of APIs, but different.
Notes: Even if we are reusing a lot across components (especially with the open sourcing last year), the reality is that each platform has its own implementation of the base libraries.
Note: .NET Framework BCL and Mono BCL are the same APIs, different implementation. .NET Core “Core Library” is a similar set of APIs, but different.
New APIs will first become available in specific .NET platforms, such as .NET Core. If the .NET Standard review board believes the new APIs should be made available everywhere, they'll be added in a new .NET Standard version.
At build time, .Net standard library bridges references to existing .net framework and PCL libraries by type forwarding
At runtime, each platform’s .net standard implementation will type forward to its corresponding implementation