什么是.NET便携式子集(旧版)?子集、旧版、NET

2023-09-02 01:55:03 作者:愿你无恙

在Visual Studio 2012的对象浏览器提供了两种不同的组件集便携式类库:

Object browser in Visual Studio 2012 offers two different component sets for Portable class libraries:

在.NET可移植的子集 在.NET便携式子集(传统)

在创建可移植类库,它使用.NET可移植的子集。什么是第二盘,我该如何使用它呢?它包含MEF这是不是在.NET便携式子集可用

When I create Portable Class Library it uses .NET Portable Subset. What is the second set and how can I use it? It contains MEF which is not available in .NET Portable Subset.

推荐答案

是的,这是令人困惑,而且基本上是因为对象浏览器并没有一个很好的方法(和没有显著我们不能添加的方式在这个版本重写)重新present便携子集。

Yep this is confusing, and is basically because Object Browser doesn't have a good way (and we couldn't add a way in this version without a significant rewrite) to represent the portable subset.

要帮助了解一些这,请考虑如下图:

To help shed some light on this, consider the following diagram:

圆圈重新present各个平台的API的表面积(不按比例)。在可移植的,我们有效地暴露存在于重叠区域的API。例如,针对所有三个以上的时候,我们让您建立针对表面面积,所有三个平台相交(即市中心)。当针对Windows应用商店和.NET Framework,我们让您建立针对交会在那两个平台的交叉(即中心和右下图)。目标更多的平台,你会得到使用减少,目标更小的平台,你会得到使用增加的表面面积的可用面积。如果你仔细想想,这是有道理的,你结合的少,他们的共同点更多的平台。

The circles represent the API surface area (not to scale) of the respective platforms. In portable, we effectively expose the APIs that exist in the overlapped areas. For example, when targeting all three above, we let you build against the surface area where all three platforms intersect (ie the very center). When targeting Windows Store and .NET Framework, we let you build against the intersection where those two platforms intersect (ie the center and bottom right). Target more platforms and the available surface area you get to use is reduced, target less platforms and the surface area you get to use is increased. If you think about it, this makes sense, the more platforms that you combine the less they have in common.

这是如何适应与你在对象浏览器中看到了什么?

在对象浏览器中,我们并没有一个简单的方法来揭露那些个别路口(当你的平台+个人版本数量的因素,还有很多!)。所以取而代之,我们做的是抓住所有可用的表面积便携式(即所有的交叉点相结合),而是公开的。这意味着,对象浏览器显示所有,我们认为便携式在所有平台上的API的组合。

In the Object Browser, we don't have an easy way to expose those individual intersections (and when you factor in the number of platforms + individual versions, there's a lot!). So instead, what we did was to grab all the available surface area in portable (ie all the intersections combined), and instead expose that. This means that the Object Browser shows you a combination of all the APIs that we consider "portable" across all of the platforms.

这就是为什么你看到的MEF。当你的目标.NET Framework和Silverlight的,但只要你添加手机或Windows应用商店,以你的目标,你失去它,因为它不支持在这些平台上MEF是可用的。

That's why you see MEF. MEF is available when you target .NET Framework and Silverlight but as soon as you add Phone or Windows Store to your targets, you lose it because it's not supported on those platforms.

什么是.NET便携式子集和.NET便携式子集(旧)之间的区别是什么?

在移动,我们有两种方法,使便携性取决于你的目标就是我们所说的传统平台和新平台。

In portable, we have two ways to enable portability depending on whether you are targeting what we call legacy platforms or new platforms.

有关传统平台(手机7.x中,SL4 / 5,.NET 4的Xbox),当我们拿出多个平台之间的交集,我们需要身体产生重新present的通用API实际组件。例如,当你把Windows Phone 7的和.NET Framework,我们生成一个实际的mscorlib程序,系统,System.Core程序等包含的API,这些股票(这些都是在我们这边微软产生)。这不仅是非常耗时,这也是因为它可以产生不是非常有用的子集极为困难。作为一个例子,当我们第一次产生的子集为跨平台的网络堆栈,存在甚至没有一种方式来创建以创建的HttpWebRequest连接的常用方法。这是因为上了年纪的平台(无论何种原因),没有人想过的便携性。

For legacy platforms (Phone 7.x, SL4/5, .NET 4, Xbox), when we come up with the intersections between multiple platforms, we need to physically generate actual assemblies that represent the common APIs. For example, when you combine Windows Phone 7 and .NET Framework, we generate (these are generated on our side in Microsoft) an actual mscorlib, system, system.core, etc that contain the APIs that these share. This is not only very time consuming, it's also extremely problematic in that it can generate not very useful subsets. As an example, when we first generated the subset for the networking stack across the platforms, there wasn't even a way to create a common way to create a HttpWebRequest connection. This was because on the older platforms (for whatever reason) no one had thought about portability.

有关新平台(.NET 4.5,Windows应用商店,手机8),我们向后退了一步,并从一开始去设计的便携性。而不是试图便携性作为一种事后,我们设计我们所说的合同(基本集)的重新present一个自包含的,单位code,无论是一个平台,支持所有的,或者没有。这意味着,当你看到System.IO 4.0.0.0上的.NET Framework 4.5,它支持完全一样的API,当你看到它在Windows Phone上,你会看到8。这让便携性很容易,而不需要产生自定义程序重新present一个平台的交叉点,我们在组件边界简单子集。例如,给定的平台1,支持System.Runtime.dll,System.Reflection.dll和System.Reflection.Emit.dll和平台2支持System.Runtime.dll和System.Reflection.dll。当你的目标在便携这些平台,我们只需选择System.Runtime.dll和System.Reflection.dll。长远来看,这使得便携性更容易理解,因为你能想到的组件,而不是个人的API的条款。

For new platforms (.NET 4.5, Windows Store, Phone 8), we took a step back and designed portability from the get go. Rather than attempt portability as an afterthought, we designed what we call contracts (basically assemblies) that represent a self-contained, unit of code that either a platform supports all of, or none of. This means that when you see "System.IO 4.0.0.0" on .NET Framework 4.5, it supports exactly the same APIs that you will see when you see it on Windows Phone 8. This makes portability very easy, rather than needing to generate custom assemblies to represent the intersection of a platform, we simply subset at the assembly boundary. For example, given a platform 1 that supports System.Runtime.dll, System.Reflection.dll and System.Reflection.Emit.dll and platform 2 that supports System.Runtime.dll and System.Reflection.dll. When you target these platforms in portable, we simply choose System.Runtime.dll and System.Reflection.dll. Long term this makes portability a lot easier to understand, as you can think in terms of assemblies instead of individual APIs.

表面积(Mscorlib中为主)被暴露遗留平台重新通过的 .NET便携式子集(传统)的,而对于新的平台,这是重新presented $ P $通过psented的 .NET可移植的子集的。

The surface area (Mscorlib-based) that are exposed for legacy platforms are represented by .NET Portable Subset (Legacy), whereas for new platforms, this is represented by .NET Portable Subset.

在使用便携,我们试图掩盖这两个表面区域,但在幕后,我们的目标对你的第一或第二表面积取决于你的目标平台。

When using portable, we attempt to hide these two surface areas, but under the covers we target your against the first or the second surface area depending on your target platforms.

这是一个很多的时间比我的计划,但随时提出澄清的问题,我一直生活和呼吸这在过去的3年,所以我倾向于跳过的东西,而不考虑这件事。

This is a lot longer than I planned, but feel free to ask clarifying questions, I've been living and breathing this for the past 3 years, so I tend to skip over things without thinking about it.