An assembly (or assembly in English) is the fundamental unit of code that the .NET Framework uses for the management, distribution, and versioning of applications.
Assemblies allow encapsulating specific functionalities that can be reused across different projects. Additionally, they can be distributed as independent files, simplifying the sharing of components or applications.
Finally, the assembly manifest allows managing different versions of the same assembly (this is very important for the correct functioning of .NET applications).
Assemblies are the basic building block with which applications in .NET are built. Let’s say that if .NET were building a building, assemblies would be the bricks you use to build the walls.
Creation and types of assembly
To create an assembly, the source code must be compiled. This process transforms the C# source code into a binary file that can be:
- Executable Assemblies (EXE): These contain an entry point, such as the
Main
method, and can be executed directly by the operating system. - Library Assemblies (DLL - Dynamic Link Library): These assemblies contain code that can be reused by other applications. They cannot be executed by themselves.
The final assembly file includes compiled code, metadata, and additional resources such as images or configuration files.
Structure of an assembly
An assembly in C# is composed of several key elements:
The C# source code is compiled into an intermediate language called IL, which is executed by the Common Language Runtime (CLR). This IL is platform-independent, allowing the same assembly to be executed in different .NET environments.
It contains information about the assembly itself, such as its version, dependencies, and security permissions. It acts as the “table of contents” of the assembly.
- Assembly name.
- Version.
- Culture.
- List of files that make up the assembly.
- Dependencies on other assemblies.
- Security permissions.
Metadata contains detailed descriptions of the types, methods, properties, and events defined in the assembly. It facilitates reflection and interoperability between languages, allowing other assemblies or applications to understand and effectively use the code.
Assemblies can include resources such as images, sound files, localized strings, and other files necessary for the application. These resources are embedded directly in the assembly, simplifying their distribution and use.