.NET class libraries

Hand

Class libraries embody the concept of a shared library in .NET. They allow you to put useful functions in modules that can be used by different applications. They can also be used to plug in functions that were not needed or not known at the time the application was started. Class libraries are described in .NET assembly file format.

There are three types of class libraries available for use:

Platform-dependent class libraries have access to all APIs on that platform (e.g., the .NET Framework in Windows, Xamarin iOS), but can only be used by applications and libraries designed for that platform.
Portable class libraries have access to a subset of the API and can be used by applications and libraries designed for multiple platforms.
.NET Standard class libraries are an amalgamation of platform-specific and portable libraries and combine the best features of both types.

Platform-specific class libraries
Platform-specific libraries are tied to a single .NET platform (such as the .NET Framework in Windows) and therefore can have many dependencies in a particular runtime environment. Such an environment provides a known set of APIs (API.NET and OS) and supports and provides the expected state (e.g. Windows registry).

Developers creating libraries for specific platforms can use all the features of the underlying platform. In doing so, such libraries will run only on that platform, which makes platform checking or other types of conditional code unnecessary (there is no single source code for multiple platforms).

Platform-specific libraries were the primary type of class library in the .NET Framework. Even after other .NET implementations came along, platform-specific libraries remained the dominant library type.

Portable Class Libraries
Portable libraries are supported in several .NET implementations. They can still have dependencies in a known runtime environment, but that environment is artificial and represents the intersection of many specific .NET implementations. The APIs and platform assumptions provided represent what would be available to a library for a particular platform.

The platform configuration is chosen when the portable library is created. The platform configuration is the set of platforms for which you need to provide support (for example, .NET Framework 4.5+ and Windows Phone 8.0+). The more platforms you choose to support, the fewer APIs and platform assumptions will be available. The principle of lowest common denominator applies here. This may seem strange, since people often think in the spirit of “the more, the better.” But in the end, it turns out that more supported platforms are associated with fewer APIs available.

Many library developers have switched from creating multiple platform-specific libraries for a single source code (using conditional compilation directives) to portable libraries. There are several approaches to accessing platform-specific functions in portable libraries. But at the moment, the most common method is the enticement mechanism.

.NET Standard class libraries;
.NET Standard libraries replace the concepts of platform-specific and portable libraries. They are platform-specific in the sense that they provide all of the functionality of the underlying platform (with no artificial platform or platform overlap). They are portable in the sense that they work on all supported platforms.

.NET Standard provides a set of library contracts. .NET implementations must support each contract fully or not at all. Thus, each implementation supports a set of .NET Standard contracts. The implication of this is that each .NET Standard class library is supported on platforms that support its contract dependencies.

.NET Standard does not provide all the functionality of the .NET Framework (and is not the goal), but the libraries do provide many more APIs than the portable class libraries.

The following implementations support the .NET Standard libraries:

  • .NET Core.
  • .NET Framework
  • Mono
  • Universal Windows Platform (UWP)
Edit