A netmodule file, also known as a managed module, is fundamentally a collection of compiled code in the .NET ecosystem. It contains Intermediate Language (IL) code and metadata, similar to a .NET Dynamic Link Library (DLL) or Executable (EXE), but it lacks the assembly manifest required to be a standalone executable or assembly.
Understanding Netmodules
Netmodules are generated by compilers (like the C# compiler, csc.exe
, or the Visual Basic compiler, vbc.exe
) when you compile source code with specific options, such as the /target:module
flag in C#. Unlike a standard compilation target that produces a DLL or EXE (which are types of .NET assemblies), compiling to a netmodule produces a file (often with a .netmodule
extension, although it can be .dll
or .exe
too) that contains compiled code but cannot be directly executed or referenced as a complete unit on its own.
The Relationship with Managed DLLs
The primary purpose of netmodules is to enable the creation of multi-module assemblies. While Managed DLLs can contain code of their own, they can also contain references to any number of netmodules.
Here's how this relationship works:
- You compile different parts of your application into separate netmodules.
- These netmodules are then linked together into a single final assembly (typically a DLL or EXE) using a tool like the .NET Linker (
al.exe
- Assembly Linker). - The resulting DLL or EXE contains the assembly manifest, which includes information about itself and references to all the netmodules that comprise it.
This approach allows for modular development and can sometimes be used for linking code written in different .NET languages into a single assembly, although direct language interop within a single compiler invocation is more common today.
Key Characteristics
- Collections of Compiled Code: They hold compiled Intermediate Language (IL) code and associated metadata.
- Lack Manifest: They do not contain an assembly manifest and therefore cannot be loaded or executed as standalone assemblies.
- Referenced by Assemblies: They are designed to be referenced by Managed DLLs or EXEs (assemblies) that do contain a manifest.
- Enable Multi-Module Assemblies: They are the building blocks for creating assemblies composed of multiple modules.
In essence, a netmodule is a compiled component that needs to be combined with others and linked into an assembly to become a usable part of a .NET application.