Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Standard, .NET Core, PCL

People also ask

Can I use .NET standard in .NET core?

. NET Core is an implementation of the . NET Standard that's optimized for building console applications, Web apps and cloud services using ASP.NET Core. Its SDK comes with a powerful tooling that in addition to Visual Studio development supports a full command line-based development workflow.

What is .NET PCL?

Portable Class Libraries (PCL)

What is the difference between .NET core and .NET Framework and .NET standard?

Application ModelsNet Core does not support desktop application development and it rather focuses on the web, windows mobile, and windows store. . Net Framework is used for the development of both desktop and web applications as well as it supports windows forms and WPF applications.

How do I use .NET standard library in .NET core?

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. I have chosen an ASP.NET Core sample Template, like the below image. Let's create another project as a simple class library.


The documents around this are indeed confusing, but it can roughly be understood as this:

  • PCL: libraries that target a set of platform (have the 'least common denominator' of APIs of those platforms). So when writing a PCL you're saying I want to target platform A, B, C

  • .NET standard: a 'standard' set of APIs rather than a platform. So basically you don't care about platforms, just the standard (version 1.3, 1.6 ...) and your code will work on all platforms that support it.

  • .NET core is not to be confused here, it's 'another version' of the .NET framework. .NET standard will work cross-runtime (.NET framework, .NET core, Mono)

So I guess .NET standard is the way to go :)


I believe this resource answers most of your questions:

https://docs.microsoft.com/en-us/dotnet/articles/standard/library

The .NET Standard Library is a formal specification of .NET APIs that are intended to be available on all .NET runtimes. The motivation behind the Standard Library is establishing greater uniformity in the .NET ecosystem.

So as I understand it, the other library types are platform specific and .NET standard is platform agnostic to a point.

If you would like your code available on different platforms then .NET standard seems ideal but pay close attention to which version of the .NET standard that the other platforms support (see table in link).

Hope this helps


This from Samuel Englard (https://github.com/dotnet/corefx/issues/973#issuecomment-249582799):

.NET DLLs are formatted according to ECMA-335 (Better known as the Common Language Infrastructure). This format is true across all platforms we call .NET; Full Framework, Core, Xamarin, Mono, Silverlight, etc.

The reason you couldn't use a DLL compiled against one platform with another was that the format didn't specify APIs (generally speaking). So while they could all read the DLL you'd run into issues of class XYZ being in namespace A.B.C on one platform and in namespace D.E.F on another, if it existed at all.

PCLs "solved" this by doing two things:

They used Type Forwarding so that even though you wrote your code expecting class XYZ in namespace A.B.C, it could be found on platforms that had it elsewhere. It limited what APIs you could use to the lowest common set shared by all the platforms you wanted.

Taking a PCL and converting it to a .NET Standard project is not a recompile because of output format but because of the meta data included (Type Forwarding particularly).

So, I think that essentially .NET Standard libraries are no different than PCL libraries except for the fact that they put a layer over the top of a different standardized set of APIs, and those APIs may implement different pointers (Type forwarding).

.NET Core is of course a runtime environment, but I think that it is just very closely aligned with .NET Standard. I don't think that it has any special relationship to it other than the fact that it implements the .NET Standard APIs.

In my mind, it is generally better to target a .NET Standard Class library because this will be compatible across multiple platforms. If you target .NET Core, this assembly type cannot be referenced in UWP for example. You will see this:

enter image description here

However, if you are working in a pure .NET Core environment, you may find that there are APIs available that are specific to the .NET Core runtime environment, and therefore it will be necessary to target .NET Core directly.

Please see this glossary: https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/glossary.md


Standard is for targeting a specific set of API similar to Android API versions. The nuget library is just meta package that contains all libraries that confirms to the standard.

Scott Hunter on MSDEV show has explained this concept very well. Worth checking it out - http://msdevshow.com/2016/07/dot-net-core-with-scott-hunter/