This documentation is archived and is not being maintained.

/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.

The file(s) you import must contain a manifest; the output file must have been compiled with one of the /target options other than /target:module.

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

See Add Reference Dialog Box.

To set this compiler option programmatically

See Add Method (References Object).


Compile source file input.cs and import metadata from metad1.dll and metad2.dll to produce out.exe:

csc /reference:metad1.dll;metad2.dll /out:out.exe input.cs

See Also

C# Compiler Options