What is the NETStandard.Library metapackage?

In my last post, 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 .NET Standard. 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 PCLs, 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 platform implements.

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 nuget.org web page for the package.

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.Collectionsfor example, 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:

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 _._ :

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):

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 ILSpy. 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:

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 Immo Landwerth on the subject.

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

from:https://andrewlock.net/what-is-the-netstandard-library-metapackage/

时间: 2024-08-01 15:33:08

What is the NETStandard.Library metapackage?的相关文章

.Net Core 中的包、元包与框架(Packages, Metapackages and Frameworks)

包,元包与框架 本文翻译自 Packages, Metapackages and Frameworks. .Net Core 是一种由 NuGet 包组成的平台.一些产品体验受益于代码包的细粒度定义,而另一些受益于粗粒度的定义,这两种定义都是有用的,不能绝对地说哪个好与不好.因此,为了适应这两种区别,一款好的产品应该可以被拆分成一组一组的细粒度的代码包,这些包之间相互独立,单个代码包的正式的名字叫做“元包”(metapackage). 每个.Net Core 包都支持运行于多种 .Net 运行时

.Net Core 学习笔记1——包、元包、框架

.Net Core 是由NuGet包(package)组成的平台. 一起使用的多个包的集合:元包(Metapackage) package 包 (对应以前的程序集概念) Framework 框架 assembly 程序集 重要的NuGet包: System.Runtime 基础包 System.Collections 泛型集合 System.Net.Http 用于HTTP网络通信 System.IO.FileSystem 读写磁盘 System.Linq 查询对象 System.Reflecti

ASP .Net Core 使用 Dapper 轻型ORM框架

一:优势 1,Dapper是一个轻型的ORM类.代码就一个SqlMapper.cs文件,编译后就40K的一个很小的Dll. 2,Dapper很快.Dapper的速度接近与IDataReader,取列表的数据超过了DataTable. 3,Dapper支持什么数据库.Dapper支持Mysql,SqlLite,Mssql2000,Mssql2005,Oracle等一系列的数据库,当然如果你知道原理也可以让它支持Mongo db 4,Dapper的r支持多表并联的对象.支持一对多 多对多的关系.并且

【无私分享:ASP.NET CORE 项目实战(第四章)】Code First 创建数据库和数据表

目录索引 [无私分享:ASP.NET CORE 项目实战]目录索引 简介 本章我们来介绍下Asp.net Core 使用 CodeFirst 创建数据库和表,通过 控制台 和 dotnet ef 两种方式 修改EF上下文对象,添加测试类 我修改了一下名字,Domains 改为了 wkmvc.Data 我们新建一个文件夹 Models 用于存放 模型类 我们在Models下面再新建一个文件夹SysModelsMange 用于区域模型类 我们新建一个测试类SYS_USER namespace wkm

Visual Studio 2013 更新 NuGet 包管理器

?  前言 使用 Visual Studio 中的 NuGet 包管理器下载程序时,有时可能出现类似的错误:"Newtonsoft.Json"已拥有为"NETStandard.Library"定义的依赖项. 解决该错误的有效办法就是更新 NuGet 包管理器,下面以 Visual Studio Ultimate 2013 为例,介绍一下更新 NuGet 包管理器的具体步骤. 1.   打开Visual Studio 2013. 2.   选择菜单栏 -> 工具

.NET Core 最小化发布

.NET Core 应用最小化独立部署发布,.NET Core 默认应用独立发布,大概占用50m左右的空间,不同的系统大小有所区别. .NET Core 的发布之前我也有所介绍,.NET Core 跨平台发布(dotnet publish) 具体可以看这篇文章. 今天来看看.NET Core 最小化发布部署,可以节省一半左右的空间. 使用 dotnet new 命令创建应用 然后打开 project.json 文件,然后将 frameworks 部分替换为以下内容:   "frameworks&

C# 6 与 .NET Core 1.0 高级编程 - 38 章 实体框架核心(上)

译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 38 章 实体框架核心(上)),不对的地方欢迎指出与交流. 章节出自<Professional C# 6 and .NET Core 1.0>.水平有限,各位阅读时仔细分辨,唯望莫误人子弟. 附英文版原文:Professional C# 6 and .NET Core 1.0 - 38 Entity Framework Core ------------------------------- 本章内容 En

ASP.NET Core 1.0 开发记录

参考页面: http://www.yuanjiaocheng.net/ASPNET-CORE/first.html http://www.yuanjiaocheng.net/ASPNET-CORE/asp-net-core-overview.html http://www.yuanjiaocheng.net/ASPNET-CORE/asp.net-core-environment.html http://www.yuanjiaocheng.net/ASPNET-CORE/newproject.h

MVC Core 网站开发(Ninesky) 2、栏目

栏目是网站的常用功能,按照惯例栏目分常规栏目,单页栏目,链接栏目三种类型,这次主要做添加栏目控制器和栏目模型两个内容,控制器这里会用到特性路由,模型放入业务逻辑层中(网站计划分数据访问.业务逻辑和Web层,初步计划划分如下图). 一.栏目控制器 1.添加控制器 在Ninesky.Web项目项目Controller文件夹点右键 添加->新建项 在添加新项对话框中选择MVC控制器类,名称输入CategoryController. 自动生成代码如下 1 using System; 2 using Sy