Portable Library, you’ll not be missed

Bye, bye portable libraries. The portable library project will not be necessary anymore. Visual Studio 2015 Update 3 offers an easy way to convert a portable library to a .NET Core library. .NET Core libraries can be used instead of portable libraries

Portable Library Settings

Silverlight and WPF

A portable library restricts types and methods within the types depending on the selections where the portable library should be used. The portable library project was created to share the same library between WPF and Silverlight applications. Depending on the version selected, the types available become restricted. The restriction not only exists with available types, but also available members of types, e.g. some methods, or overloads of some methods are not available.

At the time when the portable was created initially, the available types have been very restrictive. Over time, more and more types and methods have been added. You can, for example, create view-models within a portable library and use this library with different technologies that are based on XAML.

Portable libraries allows sharing binaries between different technologies.

A huge list of different options

Over time it was not only possible to select a specific version of Silverlight and a specific version of the .NET Framework, but also choose from specific versions for Windows 8, Universal Windows, Windows Phone, Windows Phone Silverlight, Xamarin Android, Xamarin.iOS, and Xamarin.iOS Classic. The list to manage the types and members of the types has become really complex. Now – with .NET Core – we have a new way of sharing libraries between projects using different platforms.

With .NET Core we have a new standard way for sharing libraries between different platforms.

The new definition of the types and members available is NETStandard.

NETStandard

Using Update 3 of Visual Studio 2015, you can convert a portable library to a .NET Core library. Indeed, the conversion option is already available with Update 2 of Visual Studio 2015. However, using this feature from Update 2 more problems are expected that are solved, but this feature seems to work with Update 3. At the time of this writing, the release candidate of Update 3 is available: Visual Studio 2015 Update 3 RC.

Within project properties, in the Library settings, you can select the link Target .NET Platform Standard:

Target .NET Platform Standard

Clicking this link, you can change to target the .NET Standard. After the conversion, you can select the version of the .NET Standard:

.NET Standard

At this time, you can select between version 1.0 up to version 1.5.

With this conversion, a project.json file is created with a dependency to NETStandard.Library and the supported framework netstandard1.x:

{
  "supports": {},
  "dependencies": {
    "Microsoft.NETCore.Portable.Compatibility": "1.0.1-rc2-24027",
    "NETStandard.Library": "1.5.0-rc2-24027";
  },
  "frameworks": {
    "netstandard1.1": {}
  }
}

What the .NET Standard means is best described in the document .NET Platform Standard. Within this document you can find a list which .NET CoreFX API contract (including the contract version) is supported by which version of the .NET Platform Standard: Mapping .NET CoreFX API to .NET Platform Standard. A few examples: System.Console 4.0.0 is defined with version 1.3 and up, System.Linq 4.0.0 is supported from version 1.0 to version 1.4, System.Linq 4.1.0 is supported since version 1.5. Most of the APIs are available with version 1.3 of the .NET Platform Standard.

The version of the .NET Platform Standard defines what .NET CoreFX API contract including its version number is available

There’s another important table within this document: Mapping the .NET Platform Standard to platforms. With this table you can see that .NET Framework 4.6 applications can make use of .NET Stanadard up to version 1.3. For using verison 1.4, with the .NET Framework version 4.6.1 is needed. .NET Platform Standard 1.5 does not support .NET Framework 4.6.1, and requires at least .NET Framework 4.6.2. Using Windows Phone Silverlight 8.1, the only .NET Platform Standard you can use is version 1.0.

Mappings from specific Portable Profiles can also be found within this document.

Still in use

With many scenarios, portable libraries are not needed anymore. However, there are still some scenarios where portable libraries are required. With technologies that are not further developed like Silverlight, there’s no support for .NET Core. Portable libraries are needed there for the time to come.

What you can’t find with the new .NET Standard is support for Silverlight 5. In case you’re still using Silverlight, you still need to use portable libraries.

Summary

The new .NET Standard gives an easier way to share libraries between different platforms, easier compared to portable libraries. No matter if you create WPF, UWP, ASP.NET, or Xamarin projects – you can use the new .NET Standard creating libraries. Over time every current Microsoft technology will increase its support for .NET Core. .NET Core will be used all over the place.

More Information

More information about .NET Core is in my book Professional C# 6 and .NET Core 1.0, and in my workshops.

Have fun with programming and learning!
Christian

5 thoughts on “Portable Library, you’ll not be missed

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s