BlogDevelopmentUncategorized

Going Cross Platform With Dot Net Standard

Going cross platform with.net standard

Dot Net – created by Microsoft is an open source, cross-platform software development framework. It was built with intention of deploying and running application on Windows. Dot net is now one of the most popular frameworks for developing windows applications.

Back in the early days, there was little need to share code between applications. Though sharing files was sometimes needed between client and server apps, it was infrequent. When Silverlight, a smaller, portable framework on Windows, Mac OS, and Linux was released, the developers were asked to code two versions of the same application: a full-featured version made in WPF to only run in Windows and a smaller version that ran cross-platform in Silverlight. As Silverlight plugin ran these apps outside of the browser (OOB) it was possible to build cross-platform applications. While Silverlight never made it to mobile, the need of the hour was to have the same code run on multiple platforms.

Challenges of Cross-Platform Development

As each individual platforms have specific needs, not all .NET applications can be packaged in same way. Some are wrapped into single platform specific packages, or even precompiled into machine code while others can be distributed as pure assemblies in IL. The real issue is the differences in class libraries that are available for individual .NET runtimes.

This prevents the source code from being same for all .net run times.

Below are the two approaches to overcome the problem

Code that needs to be different because of differences in the class libraries can be refactored into separate classes. So for each runtime, these classes can be implemented differently while other code can remain identical to all targeted runtimes.

Conditional compilation can be used that allows individual lines of code to differ from different runtimes in the same source code file.

Portable Class Libraries:

Portable Class Libraries (PCL) was introduced by Microsoft to make cross-platform development easier, enabling the developer to define a common set of APIs that are available in all of the targeted runtimes.
When developing a cross-platform application, common code can be put in a separate portable class library that only needs to be compiled once, and can then be referenced from other assemblies that target one of its selected target platforms. There is no need anymore to have a different class library project for each platform, and include the same source code files in these multiple platform-specific projects. In other words, all that needs to be done is UI and Data Binding of the application to be ready for Windows web and mobile, as same business logic that can be used across platforms.

The Disadvantage of PCL:

Target platform and their versions are selected in advance, to determine the intersection of the available APIs for use in the class library. This makes it impossible to target a newly released platform, or a new version of an existing platform until all the tooling is updated.

To overcome these pitfalls .Net standard has come into the picture

Dot Net Standard is built on the basic concepts of portable class Libraries. Instead of determining the common API for the targeted platforms, Dot net standard defines a set of API’s independently of them. There are multiple versions of the .net standard defined with a higher version of the standard is backward compatible with all previous versions

Dot net standard support

Developers can now select.Net standard version to target their class library. A library targeting a specific. Dotnet Standard version will work on any platform who implements this version of the standard.
If a platform is updated to support a higher version of .NET Standard, or if a new platform is released, all existing libraries targeting the newly supported version of .NET Standard will automatically work with it without any changes required by their respective authors.

NET Standard 2.0 will initially be supported by .NET framework, the Xamarin platforms and .NET Core

Author: Sigma Infosolutions

Leave a Reply