Visual Basic Compiler Options  

/addmodule

Causes the compiler to make all type information from the specified file(s) available to the project you are currently compiling.

/addmodule:module[,module2]

Arguments

module, module2
Required. A file that contains metadata but not an assembly manifest. To import more than one file, separate file names with a comma.

Remarks

module is a file created with /target:module, or another compiler's equivalent to /target:module.

All modules added with /addmodule must be in the same directory as the output file at run time. That is, you can specify a module in any directory at compile time, but the module must be in the application directory at run time. If it is not, you get a System.TypeLoadException error.

If you specify (implicitly or explicitly) any /target option other than /target:module with /addmodule, the files you pass to /addmodule become part of the project's assembly. An assembly is required to run an output file that has one or more files added with /addmodule.

Use /reference to import metadata from a file that contains an assembly.

Note   The /addmodule option is not available from within the Visual Studio development environment; it is available only when compiling from the command line. It cannot be changed programmatically.

Example

The following code creates a module:

' t1.vb
' Compile with vbc /target:module t1.vb.
' Outputs t1.netmodule.
//
Public class TestClass
   Dim i As Integer
End class

The following code imports the module's types:

' t2.vb
' Compile with vbc /addmodule:t1.netmodule t2.vb.
Option Strict Off
Module Module1
   Sub Main()
      Dim x As TestClass
      x = New TestClass
      x.i = 802
      System.Console.WriteLine(x.i)
   End Sub    
End Module

When you run t1, it outputs 802.

See Also

Visual Basic Compiler Options | /target | Sample Compilation Command Lines