Saturday, July 19, 2008

Multi-File Assemblies

Most people seem to think a .NET assembly is a file. However, assemblies can also span across multiple files or modules. An assembly essentially is a package of modules and resources with a manifest containing references to them (the manifest also stores the assembly name and version number). All of the type metadata and IL code resides within the module.

Visual Studio cannot create multi-module assemblies, but they are easy to create using the command-line compiler (csc.exe or vbc.exe) and the assembly linker (al.exe). All you need to do is compile the source code with the /target:module option and then pass, to the al.exe utility, the names of the modules as command line arguments with the /out:filename option and the /target option specifying the output type.

Example:
csc.exe /target:module /out:classlib1.netmodule classlib1.cs
csc.exe /target:module /out:program.netmodule program.cs
al.exe /target:winexe /out:program.exe classlib1.netmodule program.netmodule

No comments: