Causes the compiler to make type information in the specified assemblies available to the project you are currently compiling.
- file, file2
- One or more assemblies. To import more than one file, separate file names with a comma.
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:
- A type you use from Assembly A inherits from a type or implements an interface from Assembly B.
- You invoke a field, property, event, or method that has a return type or parameter type from Assembly B.
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
- See the Add Reference Dialog Box.
To set /reference programmatically
- See ReferencePath Property and Add Method (References Object).
The following code compiles source file
input.vb and reference assemblies from
metad2.dll to produce
vbc /reference:metad1.dll,metad2.dll /out:out.exe input.vb