There's so much happening in the .NET ecosystem nowadays. During this session, we are going to discuss innovations which are applicable for all .NET stacks – desktop, mobile, cloud and Web. We will be talking about the new standard way of creating .NET libraries - .NET Standard, about the massive changes in the project and build sub-systems brought by Visual Studio 2017 and NuGet 4.0.
4. Code sharing and library types
• Source file links
• Shared projects
• Portable class libraries (PCLs)
• .NET Standard
5. Shared projects
• Better version of the source file links
UWP project Xamarin project
File1.cs
File2.cs
SharedLib
File1.cs
File2.cs
SharedLib
File1.cs
File2.cs
SharedLibUI
App layer
UI
App layer
6. 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
7. 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
10. .NET Standard
• An evolution of PCLs, recommended approach for new libraries*
• Defines a set of APIs to be implemented by .NET platforms
(specification)
• Is versioned (API level)
• 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
• Library developers may choose target .NET Standard version
14. .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
16. Recap
• .NET Standard is the future
• project.json is obsolete
• .csproj, msbuild and NuGet play nicely together
17. Additional information
• Additions to the csproj format for .NET Core
• https://docs.microsoft.com/en-us/dotnet/articles/core/tools/csproj
• NuGet pack and restore as MSBuild targets
• https://docs.microsoft.com/en-us/nuget/schema/msbuild-targets
• How to use new features of MSBuild 15 with .NET Framework
projects
• http://lunarfrog.com/blog/how-to-use-msbuild15-net-framework
Disadvantages
Source-level sharing, no assembly
Compiler directives
Usability
Disadvantages
PCL’s require upfront decision on the supported platforms
Lowest common denominator for the selected platforms
Cannot use compiler directives
Long term maintainability