An assembly is the fundamental unit of code that the .NET Framework uses for application management, distribution, and versioning.
Assemblies allow for encapsulating specific functionality that can be reused in different projects. Furthermore, they can be distributed as independent files, simplifying the sharing of components or applications.
Finally, the assembly manifest allows for managing different versions of the same assembly (this is very important for the correct functioning of .NET applications).
Assemblies are the basic building block used to construct applications in .NET. Let’s say, if .NET were building a house, 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 which can be:
- Executable Assemblies (EXE): These contain an entry point, such as the
Mainmethod, 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 on their own.
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.
Contains information about the assembly itself, such as its version, dependencies, and security permissions. It acts as the assembly’s “table of contents.”
- Assembly name.
- Version.
- Culture.
- List of files that make up the assembly.
- Dependencies on other assemblies.
- Security permissions.
Metadata contains detailed descriptions about the types, methods, properties, and events defined in the assembly.
They facilitate reflection and language interoperability, allowing other assemblies or applications to understand and use the code effectively.
Assemblies can include resources such as images, sound files, localized strings, and other files necessary for the application. These resources are embedded directly into the assembly, simplifying their distribution and use.
