-reference (Visual Basic)-reference (Visual Basic)

使编译器让指定程序集中的类型信息可供当前正在编译的项目使用。Causes the compiler to make type information in the specified assemblies available to the project you are currently compiling.

语法Syntax

-reference:fileList  

oror

-r:fileList  

自变量Arguments

术语Term 定义Definition
fileList 必需。Required. 程序集文件名的逗号分隔列表。Comma-delimited list of assembly file names. 如果文件名包含空格,则将名称括在引号内。If the file name contains a space, enclose the name in quotation marks.

备注Remarks

导入的文件必须包含程序集元数据。The file(s) you import must contain assembly metadata. 仅公共类型在程序集外部可见。Only public types are visible outside the assembly. -addmodule 选项从模块导入元数据。The -addmodule option imports metadata from a module.

如果引用的程序集(程序集 A)引用了另一个程序集(程序集 B),那么在下列情况下需要引用程序集 B:If you reference an assembly (Assembly A) which itself references another assembly (Assembly B), you need to reference Assembly B if:

  • 程序集 A 中的类型继承自程序集 B 中的类型或实现程序集 B 中的接口。A type from Assembly A inherits from a type or implements an interface from Assembly B.

  • 调用具有程序集 B 中的返回类型或参数类型的字段、属性、事件或方法。A field, property, event, or method that has a return type or parameter type from Assembly B is invoked.

使用 -libpath 指定一个或多个程序集引用所在的目录。Use -libpath to specify the directory in which one or more of your assembly references is located.

为了使编译器能够识别程序集(而非模块)中的类型,必须强制其解析该类型。For the compiler to recognize a type in an assembly (not a module), it must be forced to resolve the type. 如何执行此操作的一个示例是定义类型的实例。One example of how you can do this is to define an instance of the type. 还可以使用其他方法来为编译器解析程序集中的类型名称。Other ways are available to resolve type names in an assembly for the compiler. 例如,如果从程序集中的类型继承,则编译器将知道类型名称。For example, if you inherit from a type in an assembly, the type name then becomes known to the compiler.

默认情况下使用 Vbc.rsp 响应文件,该文件引用常用的 .NET Framework 程序集。The Vbc.rsp response file, which references commonly used .NET Framework assemblies, is used by default. 如果希望编译器不要使用 Vbc.rsp,请使用 -noconfigUse -noconfig if you do not want the compiler to use Vbc.rsp.

-reference 的缩写形式是 -rThe short form of -reference is -r.

示例Example

下面的命令编译源文件 Input.vb 并引用来自 Metad1.dllMetad2.dll 的程序集以生成 Out.exeThe following command compiles source file Input.vb and reference assemblies from Metad1.dll and Metad2.dll to produce Out.exe.

vbc -reference:metad1.dll,metad2.dll -out:out.exe input.vb  

请参阅See also