Export (0) Print
Expand All

/lib (Specify Assembly Reference Locations)

/lib:dir1[, dir2]

where:

dir1
A directory for the compiler to look in if a referenced assembly is not found in the current working directory (the directory from which you are invoking the compiler) or in the common language runtime's system directory.
dir2
One or more additional directories to search in for assembly references. Separate additional directory names with a semicolon.

Remarks

The /lib option specifies the location of assemblies referenced by means of the /reference option.

The compiler searches for assembly references that are not fully qualified in the following order:

  1. Current working directory. This is the directory from which the compiler is invoked.
  2. The common language runtime system directory.
  3. Directories specified by /lib.
  4. Directories specified by the LIB environment variable.

Use /reference to specify an assembly reference.

/lib is additive; specifying it more than once appends to any prior values.

An alternative to using /lib is to copy into the working directory any required assemblies; this will allow you to simply pass the assembly name to /reference. You can then delete the assemblies from the working directory. Since the path to the dependent assembly is not specified in the assembly manifest, the application can be started on the target computer and will find and use the assembly in the global assembly cache.

Because the compiler can reference the assembly does not imply the common language runtime will be able to find and load the assembly at runtime. See How the Runtime Locates Assemblies for details on how the runtime searches for referenced assemblies.

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Setting Visual C# Project Properties.
  2. Click the Common Properties folder.
  3. Click the References Path property page.
  4. Modify the contents of the list box.

To set this compiler option programmatically

See ReferencePath Property.

Example

Compile t2.cs to create an .exe file. The compiler will look in the working directory and in the root directory of the C drive for assembly references.

csc /lib:c:\ /reference:t2.dll t2.cs

See Also

C# Compiler Options

Show:
© 2014 Microsoft