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!
- https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/
- https://github.com/dotnet/standard/blob/master/docs/faq.md
- https://docs.microsoft.com/en-us/dotnet/articles/standard/library
- https://github.com/dotnet/standard/blob/master/docs/netstandard-20/packaging.md
- https://www.youtube.com/watch?v=YI4MurjfMn8&list=PLRAdsfhKI4OWx321A_pr-7HhRNk7wOLLY
from:https://andrewlock.net/what-is-the-netstandard-library-metapackage/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
2012-04-12 Thread与BeginInvoke