Rediger

Del via


How to: Build a .NET Framework single-file assembly

Note

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

A single-file assembly, which is the simplest type of assembly, contains type information and implementation, as well as the assembly manifest. You can use command-line compilers or Visual Studio to create a single-file assembly that targets the .NET Framework. By default, the compiler creates an assembly file with an .exe extension.

Note

Visual Studio for C# and Visual Basic can be used only to create single-file assemblies. If you want to create multifile assemblies, you must use command-line compilers or Visual C++.

The following procedures show how to create single-file assemblies using command-line compilers.

Create an assembly with an .exe extension

At the command prompt, type the following command:

<compiler command> <module name>

In this command, compiler command is the compiler command for the language used in your code module, and module name is the name of the code module to compile into the assembly.

The following example creates an assembly named myCode.exe from a code module called myCode.

csc myCode.cs
vbc myCode.vb

Create an assembly with an .exe extension and specify the output file name

At the command prompt, type the following command:

<compiler command> /out:<file name> <module name>

In this command, compiler command is the compiler command for the language used in your code module, file name is the output file name, and module name is the name of the code module to compile into the assembly.

The following example creates an assembly named myAssembly.exe from a code module called myCode.

csc -out:myAssembly.exe myCode.cs
vbc -out:myAssembly.exe myCode.vb

Create library assemblies

A library assembly is similar to a class library. It contains types that will be referenced by other assemblies, but it has no entry point to begin execution.

To create a library assembly, at the command prompt, type the following command:

<compiler command> -t:library <module name>

In this command, compiler command is the compiler command for the language used in your code module, and module name is the name of the code module to compile into the assembly. You can also use other compiler options, such as the -out: option.

The following example creates a library assembly named myCodeAssembly.dll from a code module called myCode.

csc -out:myCodeLibrary.dll -t:library myCode.cs
vbc -out:myCodeLibrary.dll -t:library myCode.vb

See also