次の方法で共有


Building a Single-File Assembly

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 .NET to create a single-file assembly. By default, the compiler creates an assembly file with an .exe extension.

Note   Visual Studio .NET 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 Studio .NET with the Managed Extensions for C++.

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

To 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
[Visual Basic]
vbc myCode.vb

To create an assembly 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
[Visual Basic]
vbc /out:myAssembly.exe myCode.vb

Creating Library Assemblies

The previously described methods create a single-file assembly from a code module that must contain a single entry point, such as a Main or WinMain method. The compiler notifies you if the code module does not contain an entry point. If you do not want the assembly to have an entry point, create a library assembly.

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
[Visual Basic]
vbc /out:myCodeLibrary.dll /t:library myCode.vb

See Also

Creating Assemblies | Building a Multifile Assembly | Programming with Assemblies