|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
/reference (Import Metadata)
- file, file2
- One or more files that contain an assembly manifest. To import more than one file, separate file names with either a comma or a semicolon.
The /reference option causes the compiler to make public type information in the specified files available to the project you are currently compiling.
Use /addmodule to import metadata from an output file that does not contain an assembly manifest.
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, do not pass an assembly built with /target:exe or /target:winexe to /reference. This condition may be modified in future versions of the common language runtime.
If you reference an assembly (Assembly A), which itself 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.
- If you invoke a field, property, event, or method that has a return type or parameter type from Assembly B.
Use /lib to specify the directory in which one or more of your assembly references is located. The /lib topic also discusses which directories the compiler searches for assemblies.
In order for the compiler to recognize a type in an assembly (not a module), it needs to be forced to resolve the type, which you can do, for example, 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 become known to the compiler.
The csc.rsp response file, which references commonly-used .NET Framework assemblies, is used by default. Use /noconfig if you do not want the compiler to use csc.rsp.
/r is the short form of /reference.
To set this compiler option in the Visual Studio development environment
To set this compiler option programmatically
See Add Method (References Object).
Compile source file
input.cs and import metadata from
metad2.dll to produce
csc /reference:metad1.dll;metad2.dll /out:out.exe input.cs