为什么某些NuGet软件包同时提供了可移植库和特定于平台的库? [英] Why do some NuGet packages provide both a Portable Library and an Platform Specific One?

查看:72
本文介绍了为什么某些NuGet软件包同时提供了可移植库和特定于平台的库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,可移植类库可以在许多平台上使用,这是基于库的设计者选择支持的框架子集来实现的.

我注意到NuGet提供的许多库还包括特定于平台的实现,并想知道对此有何需求.

例如, Microsoft.Net.Http 程序包具有许多变体,包括: /p>

  • Net 4.0版本
  • WinRT(Windows应用商店应用程序)Windows 8版本
  • 支持Net 4.0,WinRT等的便携式类库

为什么需要分发单独的.Net 4.0或WinRT版本的库? 便携式类库不够吗?

在设计自己的自定义便携式图书馆时,我应该遵守这个约定吗?

为了清楚起见,我并不是在谈论需要一小部分特定于平台的代码才能工作的可移植类库.它们通常具有一个随附的托管库,其名称以.PlatformServices结尾.但是我说的是NuGet软件包分发的核心库.

解决方案

当然,PCL版本可能足以满足您的需求.但是,当您一定要找到创建自己的PCL类库项目时,实际上可以在PCL项目中使用的.NET Framework类和方法的子集是一个很小的子集.通过采用完整的.NET Framework并减去在其他平台上无法使用的部分,可以创建该子集.

限制性最强的平台是Silverlight和Phone7,它们基于CLR的.NETCore版本.以及Store和Phone8,基于可通过WinRT API获得的服务.针对这些目标中的任何一个,都会迅速减少您可以在库中执行的操作.

Microsoft.Net.Http软件包经过优化,如果您不受那些受限平台之一的限制,仍然可以使用一些与Http相关的方法和属性.您可以在package子目录中进行查看,该目录提供了IntelliSense,该System.Net.Http.Extensions.xml文件向您展示了在一个平台上可能发生的事情,而在另一平台上却没有.我看到了:

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

请注意,这些属性是使用扩展方法映射的.

It is my understanding that Portable Class Libraries can be used on many platforms, based upon the subset of the framework the designer of the library choose to support.

I noticed that many libraries available via NuGet also include a platform specific implementation and wonder what is the need for this.

For instance, the Microsoft.Net.Http package comes with many variations, including :

  • Net 4.0 version
  • WinRT (Windows Store Apps) Windows 8 Version
  • Portable Class Library supporting Net 4.0, WinRT and others

Why is there a need to distribute separate .Net 4.0 or WinRT versions of the Library ? Isn't the Portable Class Library sufficient ?

When I'm designing my own custom Portable Libraries, should I adhere to this convention ?

To be clear, I'm not talking about Portable Class Libraries that need a small portion of platform specific code to work. Those usually have an accompanying managed Library whose name ends with .PlatformServices. But I'm talking about the core library distributed by the NuGet package.

解决方案

Sure, the PCL version might well be sufficient for your needs. However, as you are bound to find out when you create your own PCL class library project, the sub-set of .NET Framework classes and methods that you can actually use in a PCL project is a rather small one. That sub-set is created by taking the full .NET Framework and subtracting out the parts that cannot work on another platform.

The most restrictive platforms are Silverlight and Phone7, they are based on the .NETCore version of the CLR. And Store and Phone8, based on the services available through the WinRT api. Targeting any of these quickly dwindles down the number of things you can do in your library.

The Microsoft.Net.Http package was optimized to still make some of the Http relevant methods and properties available if you are not limited by one of those restricted platforms. You can have a look-see in the packages subdirectory, the System.Net.Http.Extensions.xml files that provide IntelliSense shows you what is possible on one platform but not another. I see:

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

Do note that these properties are mapped with extension methods.

这篇关于为什么某些NuGet软件包同时提供了可移植库和特定于平台的库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆