Click here to Skip to main content
12,758,605 members (32,050 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.9K views
4 bookmarked
Posted 18 Nov 2016

.Net Standard

, 18 Nov 2016 CPOL
Rate this:
Please Sign up or sign in to vote.
In this post we will explore in details of how we can share code without too much headache of targeted platform/environment.

First we will focus on Portable Class Library (PCL) then we will replace it by .Net Standard.

Portable Class Library (PCL)

PCL is all about sharing the code across several targeted platform. Its main goal is to re-use the code across different types of .Net application with targeted platforms.

Let’s create a new .Net Core application to reference a normal class library whether it work’s or not.

Open Visual Studio 2015 Go to menu click File> New> Project then choose .net Core from left menu by selecting ASP.NET Core Web Application like below image.

std_1

I have choose ASP.NET Core sample Template, like below image.

std_2

Let’s create another project as simple class library.

std_3

Notice that we are targeting .Net Framework 4.6.1.

std_4

Here we can see a warning while we are going to reference it in our ASP.NET Core sample application.

std_5

.Net Framework 4.6.1 is unsupported by .Net Core Application with the version of 1.0, how we can solve this. Now let’s create another class library which is portable with the specific targeting platform.

std_6

Configure the target options.

std_7

.Net Framework 4.6 which is supporting same set of portable APIs as .Net Framework 4.5. So it will automatically targeted to .Net Framework 4.5.

Go to properties of the portable class library we can see we have targeted the .Net Framework 4.5, ASP.NET Core 1.0, Windows 8

std_8

Reference it to our .Net Core Application.

std_9

According to the below diagram, we have now three different Base Class Library (BCL) that is targeted to specific environment. The problem here is writing code for multiple .NET platforms. It is also hard to figure out supported APIs on different platforms.

dotnet-today

Image: blogs.msdn.microsoft.com

What if we have a Unified Base Class Library?

Here come’s .NET Platform Standard as Unified Base Class Library which run on all .NET platforms.

.NET Standard

Previously named .NET Platform Standard is a set of API’s that work on all .NET runtimes. Code sharing problem is now more simplified by .Net Standard. We can simply replace Portable Class Library (PCL) by .Net Standard.

dotnet-tomorrow

Image: blogs.msdn.microsoft.com

With .Net Standard we are not targeting to specific platform but we are working with different version of .Net Standard that is supported by cross platform/environment.

std_10

We can convert our existing PCL to .Net Standard Library by Clicking on Target .Net Platform Standard as above picture.

Warning with change effect will appear, click “Yes”, it will make change the library.

std_11

New file named project.json will created automatically with the target environment information.

std_12

Project.json

std_13

.NET Standard Version

std_14

Image: blogs.msdn.microsoft.com

From the upper version matrix table – .NET Core 1.0 targeted the .NET Standard version 1.6 it will work with all the lower versions of 1.0 – 1.5.

Summary

  • .NET Standard – Work on Cross .NET runtimes (.NET framework, .NET core, Mono)
  • Portable Class Library (PCL) – Work on targeted .NET platforms (.NET framework 4.5, ASP .NET core 1.1, Windows 8)

References

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Shashangka Shekhar
Software Developer (Senior) Amber Group
Bangladesh Bangladesh
Hi, I am Shashangka Shekhar,

Working with Microsoft Technologies. Since March 2011, it was my first step to working with Microsoft Technologies, achieved bachelor’s degree on Computer Science from State University of Bangladesh(Dhaka). Have 5+ years of professional experience, currently working as Senior Software Engineer at Amber Group(MIS).

I believe in desire of learning & also love to be a part of .Net Community by sharing knowledge’s.

You may also be interested in...

Pro

Comments and Discussions

 
QuestionThanks Bro Pin
mahfuzbappy21-Nov-16 4:39
professionalmahfuzbappy21-Nov-16 4:39 
AnswerRe: Thanks Bro Pin
Shashangka Shekhar21-Nov-16 4:57
memberShashangka Shekhar21-Nov-16 4:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 19 Nov 2016
Article Copyright 2016 by Shashangka Shekhar
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid