Rediger

Del via


Multifile assemblies

Note

This article is specific to .NET Framework. It doesn't apply to newer implementations of .NET, including .NET 6 and later versions.

You can create multifile assemblies that target the .NET Framework using command-line compilers or Visual Studio with Visual C++. One file in the assembly must contain the assembly manifest. An assembly that starts an application must also contain an entry point, such as a Main or WinMain method.

For example, suppose you have an application that contains two code modules, Client.cs and Stringer.cs. Stringer.cs creates the myStringer namespace that is referenced by the code in Client.cs. Client.cs contains the Main method, which is the application's entry point. In this example, you compile the two code modules, and then create a third file that contains the assembly manifest, which launches the application. The assembly manifest references both the Client and Stringer modules.

Note

Multifile assemblies can have only one entry point, even if the assembly has multiple code modules.

There are several reasons you might want to create a multifile assembly:

  • To combine modules written in different languages. This is the most common reason for creating a multifile assembly.

  • To optimize downloading an application by putting seldom-used types in a module that's downloaded only when needed.

  • To combine code modules written by several developers. Although each developer can compile each code module into an assembly, this can force some types to be exposed publicly that are not exposed if all modules are put into a multifile assembly.

Once you create the assembly, you can sign the file that contains the assembly manifest, and hence the assembly, or you can give the file and the assembly a strong name and put it in the global assembly cache.

See also