博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
What is the NETStandard.Library metapackage?
阅读量:7050 次
发布时间:2019-06-28

本文共 4621 字,大约阅读时间需要 15 分钟。

In my , I took a quick look at the Microsoft.AspNetCore meta package. One of the libraries referenced by the package, is the NETStandard.Library NuGet package. In this post I take a quick look at this package and what it contains.

If you're reading this post, you have hopefully already heard of . This is acts as an interface to .NET Platforms, and aims to define a unified set of APIs that those platforms must implement. It is the spiritual successor to , and allow you to target .NET Framework, .NET Core, and other .NET platforms with the same library code base.

The NETStandard.Library metapackage references a set of NuGet packages that define the .NET Standard library. Like the Microsoft.AspNetCore package from my last post, the package does not contain dlls itself, but rather references a number of other packages, hence the name metapackage. Depending on the target platform of your project, different packages will be added to the project, in line with the appropriate version of .NET Standard the .

For example, the .NET Standard 1.3 dependencies for the NETStandard.Library package includes the System.Security.Cryptography.X509Certificates package, but this does not appear in the 1.0, 1.1 or 1.2 target platforms. You can also see this on the .

It's worth noting that the NETStandard.Library package will typically be referenced by projects, though not by libraries. It's also worth noting that the version number of the package does not correspond to the version of .NET Standard, it is just the package version.

So even if your project is targeting .NET Standard version 1.3 (or multi-targeting), you can still use the latest NETStandard.Library package version (1.6.1 at the time of writing). The package itself is versioned primarily because it also contains various tooling support such as the list of .NET Standard versions.

It's also worth bearing in mind that the NETStandard.Library is essentially only an API definition, it does not contain the actual implementation itself - that comes from the underlying platform that implements the standard, such as the .NET Framework or .NET Core.

If you download one of the packages referenced in the NETStandard.Library package, System.Collections, and open up the nuget package as before, you'll see there's a lot more too it than the Microsoft.AspNetCore metapackage. In particular, there's a lib folder and a ref folder:

System.Collections 4.3

In a typical NuGet package, lib is where the actual dlls for the package would live. However, if we do a search for all the files in the lib folder, you can see that there aren't actually any dlls, just a whole load of empty placeholder files called _._ :

Lib folder

So if there aren't any dlls in here, where are they? Taking a look through the ref folder you find a similar thing - mostly _._ placeholders. However that's not entirely the case. The netstandard1.0 and netstandard 1.3 folders do contain a dll (and a load of xml metadata files):

Refs folder

But look at the size of that System.Collections.dll - only 42kb! Remember, the NETStandard.Library only includes reference assemblies, not the actual implementations. The implementation comes from the final platform you target; for example .NET Framework 4.6.1, .NET Core or Mono etc. The reference dlls just define the various APIs that these platforms must expose for a given version of .NET Standard.

You can see this for yourself by decompiling the contained dll using something like . If you do that, you can see what looks likes the source code for System.Collections, but without any method bodies, showing that this really is just a reference assembly:

ILSpy of System.Collections

These placeholder assemblies are are a key part of the the .NET Standard infrastructure. They provide concrete APIs against which you can compile your projects, without tying you to a specific implementation (i.e. .NET Framework or .NET Core).

Final thoughts

If this all seems confusing and convoluted, that's because it is! It doesn't that every time you think you've got your head around it, things have moved on, are being changed or improved…

Having said that, most of this is more detail than you'll need. Generally, it's enough to understand the broad concept of .NET Standard, and the fact that it allows you to share code between multiple platforms.

There's a whole host of bits I haven't gone into, such as type forwarding, so if you want to get further into the details, and really try to understand what's going on, I suggest checking out the links below. In particular, I highly recommend the video series by  on the subject.

Of course, when .NET Standard 2.0 is out, all this will change again, so brace yourself!

 

from:

转载地址:http://nypol.baihongyu.com/

你可能感兴趣的文章
MySQL单机多实例安装并配置主从复制
查看>>
awk调用shell命令的两种方法:system与print
查看>>
网络对抗技术 20164320 王浩 Exp 9 Web安全基础
查看>>
谷歌开源第二代机器学习系统 TensorFlow
查看>>
juqery模板 Templates
查看>>
eclipse 自动创建web.xml
查看>>
python 基础回顾2
查看>>
Servlet 示例
查看>>
十一.单表更新及多表更新
查看>>
深入理解DOM节点类型第三篇——注释节点和文档类型节点
查看>>
32位64位操作系统基本数据类型字节大小
查看>>
linux高级编程day04 笔记
查看>>
CF848C:Goodbye Souvenir(CDQ分治)
查看>>
BZOJ 1006: [HNOI2008]神奇的国度
查看>>
PHP+mysql系统报错:PHP message: PHP Warning: Unknown: Failed to write session data (files)
查看>>
反向代理负载均衡之APACHE
查看>>
Django 安装
查看>>
jQuery用unbind方法去掉hover事件及其他方法介绍
查看>>
Centos Git1.7.1升级到Git2.2.1
查看>>
linux修改PS1,自定义命令提示符样式
查看>>