/reference (Import Metadata) (C# Compiler Options)
The /reference option causes the compiler to importtype information in the specified file into the current project, thus enabling you to reference metadata from the specified assembly files.
To import from more than one file, include a /reference option for each file.
The files you import must contain a manifest; the output file must have been compiled with one of theoptions other than .
/r is the short form of /reference.
Useto import metadata from an output file that does not contain an assembly manifest.
If you reference an assembly (Assembly A) that references another assembly (Assembly B), you will 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.
Useto specify the directory in which one or more of your assembly references is located. The /lib topic also discusses the directories in which the compiler searches for assemblies.
In order for the compiler to recognize a type in an assembly, and not in a module, it needs to be forced to resolve the type, which you can do by defining an instance of the type. There are other ways to resolve type names in an assembly for the compiler: for example, if you inherit from a type in an assembly, the type name will then be recognized by the compiler.
Sometimes it is necessary to reference two different versions of the same component from within one assembly. To do this, use the alias suboption on the /reference switch for each file to distinguish between the two files. This alias will be used as a qualifier for the component name, and will resolve to the component in one of the files.
The csc response (.rsp) file, which references commonly used .NET Framework assemblies, is used by default. Useif you do not want the compiler to use csc.rsp.
For more information, see.
This example shows how to use thefeature.
You compile the source file and import metadata from grid.dll and grid20.dll, which have been compiled previously. The two DLLs contain separate versions of the same component, and you use two /reference with alias options to compile the source file. The options look like this:
/reference:GridV1=grid.dll and /reference:GridV2=grid20.dll
This sets up the external aliases "GridV1" and "GridV2," which you use in your program by means of an extern statement:
extern GridV1; extern GridV2; // Using statements go here.
Once this is done, you can refer to the grid control from grid.dll by prefixing the control name with GridV1, like this:
In addition, you can refer to the grid control from grid20.dll by prefixing the control name with GridV2 like this: