Portable, shared, net-standard libraries – so many options to choose when you need to share some code between the platforms. During this talk we will explore all the options and differences between the library types. After the session you will have a solid understanding of the modern .NET library types and code sharing strategies which you can apply for your next .NET Core, desktop or Xamarin project.
6. Shared projects
• Benefits
• Simple model
• May include platform-specific code
• Disadvantages
• Source-level sharing, no assembly
• Compiler directives
• Usability
7. Portable class libraries
• Sharing code in binary form, without recompiling
UWP project Xamarin project
File1.cs
File2.cs
PortableLib
UI
App layer
UI
App layer
8. How it works?
• PCLs are based on profiles
• Profile defines an API surface supported by the library
• Profile is identified by combination of supported platforms
• http://embed.plnkr.co/03ck2dCtnJogBKHJ9EjY
• C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortable
11. Portable class libraries
• Benefits
• PCLs allow binary distribution
• API enforcement
• No context switching, simple refactoring
• Disadvantages
• PCL’s require upfront decision on the supported platforms
• Lowest common denominator for the selected platforms
• Cannot use compiler directives
• Long term maintainability
12. .NET Standard
• An evolution of PCLs
• .NET Standard defines a set of APIs to be implemented by .NET
platforms (specification)
• .NET Standard is versioned (API level)
• Library developers may choose target .NET Standard version
• Version defines API surface, not supported frameworks
• The higher the version, the more APIs you have
• The lower the version, the more .NET platforms implement it
• Analogy: https://gist.github.com/davidfowl/8939f305567e1755412d6dc0b8baf1b7
17. .NET Standard
• Current state
• Tooling is in preview
• Currently PCLs support a wider range of platforms
• At the moment, PCL adoption (# of libraries) is higher than .NET Standard
• Future
• PCL replacement
• Standard 2.0 will have significantly larger API surface
• Standard 2.0 will be interoperable with .NET Framework