.Net Assembly and Module

时不时地在.Net中接触到module这个概念,费解了好久。

先说说Assembly吧,一个dll或者一个exe就是一个assembly。
Physically, we can compile related code files into an assembly. Assembly is the minimum unit of deployment.
Logically, an assembly can have one or more modules which are collections of code.

Assemblies contain modules. Modules contain classes. Classes contain functions.

一个assembly里面,除了若干个module,还有一个manifest,包含了这个dll的描述信息。The manifest is the metadata of the dll.
可以用Ildasm.exe (C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools) 来打开assembly。

可以看到MANIFEST和module里面的内容。

MANIFEST里面有reference的内容,引用了AutoFac,有token和版本。下面还有module的列表,这个exe里面只有CSharpLearning.exe一个module。

本来module的意义是在代码物理区隔层面上再加一层逻辑区隔。不过大概后来发现多这么一层的意义也不是很大,于是.Net默认一个Assembly里面只有一个Module。

Leave a comment