-addmodule-addmodule

使编译器让指定文件中的所有类型信息可供当前正在编译的项目使用。Causes the compiler to make all type information from the specified file(s) available to the project you are currently compiling.

语法Syntax

-addmodule:fileList  

自变量Arguments

fileList
必需。Required. 包含元数据但不包含程序集清单的文件的逗号分隔列表。Comma-delimited list of files that contain metadata but do not contain assembly manifests. 包含空格的文件名称应括在引号 (" ") 中。File names containing spaces should be surrounded by quotation marks (" ").

备注Remarks

fileList 参数列出的文件必须使用 -target:module 选项生成,或者使用其它编译器的 -target:module 等效项。The files listed by the fileList parameter must be created with the -target:module option, or with another compiler's equivalent to -target:module.

通过 -addmodule 添加的所有模块在运行时必须位于与输出文件相同的目录中。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. 若非如此,你会获得 TypeLoadException 错误。If it is not, you get a TypeLoadException error.

若你使用 -addmodule 指定(隐式或显式)除 -target:module 之外的任何 -target (Visual Basic) 选项,传递给 -addmodule 的文件会成为该项目的程序集的一部分。If you specify (implicitly or explicitly) any-target (Visual Basic) option other than -target:module with -addmodule, the files you pass to -addmodule become part of the project's assembly. 必须具有程序集,才能运行包含一个或多个由 -addmodule 添加的文件的输出文件。An assembly is required to run an output file that has one or more files added with -addmodule.

使用 -reference (Visual Basic) 从包含程序集的文件导入元数据。Use -reference (Visual Basic) to import metadata from a file that contains an assembly.

备注

-addmodule 选项在 Visual Studio 开发环境内无法使用;仅当从命令行编译时才可用。The -addmodule option is not available from within the Visual Studio development environment; it is available only when compiling from the command line.

示例Example

下面的代码创建模块。The following code creates a module.

' t1.vb
' Compile with vbc /target:module t1.vb.
' Outputs t1.netmodule.

Public Class TestClass
    Public 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

Namespace NetmoduleTest
    Module Module1
        Sub Main()
            Dim x As TestClass
            x = New TestClass
            x.i = 802
            System.Console.WriteLine(x.i)
        End Sub
    End Module
End Namespace

运行 t1 时,它会输出 802When you run t1, it outputs 802.

请参阅See also