Visual Basic Compiler Options  

/reference

Causes the compiler to make type information in the specified assemblies available to the project you are currently compiling.

/reference:file[,file2]

-or-

/r:file[,file2]

Arguments

file, file2
One or more assemblies. To import more than one file, separate file names with a comma.

Remarks

The file(s) you import must contain assembly metadata. Only public types are visible outside the assembly. /addmodule imports metadata from a module.

At run time, you should anticipate that only one .exe assembly can be loaded per process, even though there may be times when more than one .exe might be loaded in the same process. Therefore, it is not recommended to pass an assembly built with /target:exe or /target:winexe to /reference if you are compiling with /target:winexe or /target:exe.

If you reference an assembly (Assembly A) which itself references another assembly (Assembly B), you need to reference Assembly B if:

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, which you can do, for example, by defining 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.

/r is the short form of /reference.

To set /reference in the Visual Studio integrated development environment

To set /reference programmatically

Example

The following code 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

Visual Basic Compiler Options | /target | /target:module | Public | Sample Compilation Command Lines