Why do some NuGet packages provide both a portable library and a platform?

I understand that Portable Class Libraries can be used on many platforms, based on a subset of the structure that the library developer prefers to support.

I noticed that many of the libraries available through NuGet also include an implementation on the platform and wonder what is needed for this.

For example, the Microsoft.Net.Http package comes with many options, including:

  • Net Version 4.0
  • WinRT (applications for the Windows Store) Version for Windows 8
  • A portable class library that supports Net 4.0, WinRT and others.

Why is there a need to distribute individual versions of the .NET or WinRT library? Is a portable class library sufficient?

When I develop my own portable libraries, should I adhere to this agreement?

To be clear, I'm not talking about portable class libraries, which require a small amount of code on the platform to work. Usually they have an maintained managed library whose name ends with .PlatformServices. But I'm talking about the main library distributed by the NuGet package.

+6
source share
1 answer

Of course, the PCL version may well be sufficient for your needs. However, since you will definitely find out when you create your own PCL class library project, the subset of the .NET Framework classes and methods that you can really use in a PCL project is quite small. This subset is created by the full .NET Framework and subtracting parts that cannot work on another platform.

The most restrictive platforms are Silverlight and Phone7; they are based on the .NETCore CLR version. Both Store and Phone8 based on services available through the WinRT api. Focusing on any of them quickly reduces the number of things you can do in your library.

The Microsoft.Net.Http package has been optimized to continue to use some of the appropriate Http methods and properties if you are not limited to one of these limited platforms. You can look in the package subdirectory, the System.Net.Http.Extensions.xml files that IntelliSense provides show you what is possible on one platform, but not another. I see:

  • HttpWebRequest.AllowAutoRedirect
  • AuthenticationManager.PreAuthenticate
  • HttpWebRequest.ProtocolVersion
  • HttpRequestHeaders.TransferEncodingChunked
  • HttpClientHandler.UseProxy

Note that these properties are displayed using extension methods.

+5
source

All Articles