What exactly is an Assembly in C# or .NET?

2020-02-07 14:28发布

Could you please explain what is an Assembly in C# or .NET?

  1. Where does it begin and where does it end?
  2. What important information should I know about Assemblies?

9条回答
The star\"
2楼-- · 2020-02-07 14:55

.NET assembly

In the Microsoft .NET framework, an assembly is a partially compiled code library for use in deployment, versioning and security.

查看更多
够拽才男人
3楼-- · 2020-02-07 14:56

When a source code is compiled by the language compiler it Generate a Managed Assembly and MSIL(MisroSoft Intermediate Language). That Assembly contains .dll or .exe file. An Assebmly can be of two types Private Assembly and Shared Assembly, shared Assembly is stored in GAC(Global Assembly Cache) so that any application can refer to it while private assembly is stored in application folder which can be used by only one Application.

查看更多
祖国的老花朵
4楼-- · 2020-02-07 15:03

An assembly is the compiled output of your code, typically a DLL, but your EXE is also an assembly. It's the smallest unit of deployment for any .NET project.

The assembly typically contains .NET code in MSIL (Microsoft Intermediate language) that will be compiled to native code ("JITted" - compiled by the Just-In-Time compiler) the first time it is executed on a given machine. That compiled code will also be stored in the assembly and reused on subsequent calls.

The assembly can also contain resources like icons, bitmaps, string tables and so on. Furthermore, the assembly also contains metadata in the assembly manifest - information like version number, strong name, culture, referenced assemblies and so forth.

In 99% of your cases, one assembly equals a physical file on disk - the case of a multi-file assembly (one assembly, distributed across more than a single file) appears to be a rather odd-ball edge case which I've never encountered so far in my 5+ years of .NET development.

In a multifile assembly there would still be only one assembly manifest in a DLL or EXE and the MSIL code in multiple netmodule files.

查看更多
登录 后发表回答