简体   繁体   English

净标准包装

[英]Net standard package

I've been researching a whole day about .NET Standard and its integration with multiple frameworks; 我整天都在研究.NET Standard及其与多个框架的集成。 I think i get it all, but only one question wanders in my mind and its related to the package inclusion. 我想我已经掌握了所有内容,但是在我的脑海中只有一个问题徘徊,它与软件包包含的内容有关。

For example, i am targeting the net standard 1.6 and when i look at the assemblies list in visual studio 2017 i can see: "System.Reflection (4.3.0)" . 例如,我的目标是网络标准1.6 ,当我查看Visual Studio 2017中的程序集列表时,我可以看到: “ System.Reflection(4.3.0)” Meaning that i have support for that version of the assembly, but the API specs for the net standard version says that it doesn't support for example "System.Reflection.Emit.ILGeneration" . 这意味着我支持该版本的程序集,但是对于网络标准版本的API规范说,它不支持例如“ System.Reflection.Emit.ILGeneration”

So what happens if i add the package ILGeneration 4.3.0 ; 因此,如果我添加软件包ILGeneration 4.3.0会发生什么? According to the package i need support for: 根据包装,我需要支持:

System.Reflection (>= 4.3.0)
System.Reflection.Primitives (>= 4.3.0)
System.Runtime (>= 4.3.0)

Which i have according to the assemblies list, so my questions are: 根据组装清单我有哪些,所以我的问题是:

  • The reason why ILGeneration is not implemented in the API specs its caused Xamarin.iOS doesnt have DLR support (AOT compiler)? API规范中未实现ILGeneration的原因是Xamarin.iOS不支持DLR(AOT编译器)吗?
  • Would adding the package could potentially mess with another library or framework that is using net standard 1.6 in case of reference? 在引用的情况下,添加该软件包是否有可能与使用Net Standard 1.6的另一个库或框架发生混乱? (ignoring Xamarin.iOS) (忽略Xamarin.iOS)
  • What stops me from just using conditional compilation and just remove ILGeneration package if i am using Xamarin.iOS or any of the potential conflicts with other implementations? 如果我使用Xamarin.iOS或与其他实现的任何潜在冲突,是什么使我无法仅使用条件编译并删除ILGeneration包? (assuming the last question is true). (假设最后一个问题是正确的)。

Thanks in advance. 提前致谢。

The big difference here is that there are some APIs that are in / part of .NET Standard and some packages that are built on top of it. 此处的最大区别是,.NET Standard 中的/部分包含一些API,并且基础上构建了一些软件包。

In .NET Standard < 2.0, "the standard" is defined by the closure of packages that the NETStandard.Library package brings in. System.Reflection.Emit.ILGeneration is then considered to be outside of the standard but should work for most platforms supporting the .NET Standard because it is built on top of it - for ILGeneration in particular, this may not be exactly true since it is tied closely to the underlying runtimes. 在.NET标准<2.0,“标准”是由包的闭合所定义的NETStandard.Library包中带来的。 System.Reflection.Emit.ILGeneration然后被认为是标准的外部,但应用于支承最平台上工作.NET Standard,因为它是基于它构建的-特别是对于ILGeneration,由于它与基础运行时紧密相关,因此可能并不完全正确。 But the point is that packages built on top of the standard can offer api but choose to throw exceptions when a particular platform doesn't support a feature. 但关键是,基于标准构建的软件包可以提供api,但是当特定平台不支持功能时,选择抛出异常。

Instead of referencing NETStandard.Library , packages built from CoreFX reference the individual packages to avoid some chicken-and-egg problem ( NETStandard.Library and Microsoft.NETCore.App are mostly just collection of their packages). CoreFX构建的程序包不会引用NETStandard.Library而是引用各个程序包,以避免出现鸡毛蛋的问题( NETStandard.LibraryMicrosoft.NETCore.App通常只是它们程序包的集合)。 Some other 3rd party libraries do this as well, but this setup is discouraged for new projects since some fixes come in via updates to NETStandard.Library . 其他一些第三方库也可以这样做,但是对于新项目不建议使用此设置,因为通过NETStandard.Library更新可以修复一些NETStandard.Library

A weird side-effect of Microsoft.NETCore.App being composed of packages is that there are a few packages built for .NET Standard 1.6 are bringing in implementations rather than just defining "a contract". 由包组成的Microsoft.NETCore.App怪异副作用是,为.NET Standard 1.6构建的一些包引入了实现,而不仅仅是定义“合同”。

For .NET Core 2.0 and .NET Standard 2.0, this setup changes a bit since the two packages NETStandard.Library and Microsoft.NETCore.App are no longer "meta-packages", but flat packages containing a bunch of dlls (and even native assets for self-contained applications). 对于.NET Core 2.0和.NET Standard 2.0,此设置有所变化,因为两个软件包NETStandard.LibraryMicrosoft.NETCore.App不再是“元软件包”,而是包含一堆dll(甚至是本地dll)的扁平软件包。独立应用的资产)。 Also a library built for netstandard2.0 will contain no package references by default when publishing - the API of .NET Standard is considered to be brought in by the platform. 同样,为netstandard2.0构建的库在发布时默认情况下将不包含任何程序包引用-平台netstandard2.0 .NET Standard的API引入。

With this in mind, lets look at your questions: 考虑到这一点,让我们看一下您的问题:

  1. The reasons for IL generation not being part of the standard is most likely the AOT compilation limitations. IL生成不属于标准的原因很可能是AOT编译的局限性。 This includes Xamarin iOS but may also apply to .NET Native and CoreRT. 这包括Xamarin iOS,但也可能适用于.NET Native和CoreRT。 Since not all platforms are required to implement the API, this is considered an "extension to the standard" so it may not work on all platforms, even if they support .NET Standard 1.6 由于并非所有平台都需要实现API,因此这被视为“标准的扩展”,因此,即使它们支持.NET Standard 1.6,也可能不适用于所有平台。

  2. Only if this other project needs to run on a platform that does not support the APIs in question. 仅当该其他项目需要在不支持所讨论的API的平台上运行时。 The limits introduces by using this package applies transitively to all projects referencing it. 使用此软件包引入的限制会暂时应用于引用该软件包的所有项目。

  3. Only your features :) The .NET SDK doesn't support Xamarin target frameworks by default but by using the MSBuild.Sdk.Extras NuGet package you can create a library that multi-targets .NET Standard and Xamarin iOS. 仅您的功能:)默认情况下,.NET SDK不支持Xamarin目标框架,但是通过使用MSBuild.Sdk.Extras NuGet包,您可以创建一个多目标.NET Standard和Xamarin iOS的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM