Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

How to: Add or Remove References in Visual Studio 

NoteNote

The procedure for setting the reference path for Visual C# and Visual J# projects is slightly different. In a Visual Basic project, click the Reference Paths button to bring up the Add Reference dialog box. In a Visual C# or Visual J# project, use the Reference Paths Page, Project Designer (C#, J#) of the Project Designer. For more information, see How to: Set the Reference Path (C#, J#).

In order to use a component in your application, you must first add a reference to it. Visual Studio provides five options in the Add Reference Dialog Box:

  • .NET lists all .NET Framework components available for referencing.

  • COM lists all COM components available for referencing.

  • Projects lists all reusable components created from local projects.

  • Browse allows you to browse for a component in the file system.

  • Recent contains a list of components recently added to projects on your computer.

The Add Reference dialog box only lists assemblies in the Public Assemblies folder (Program Files\Microsoft Visual Studio .NET\Common7\IDE\Public Assemblies). You can copy your own assemblies to the Public Assemblies folder, or browse to them directly. Note that you cannot add references from the Global Assembly Cache (GAC), as it is strictly part of the run-time environment.

If you deploy or copy an application that contains a reference to a custom component registered in the GAC, the component will not be deployed or copied with the application, regardless of the Copy Local setting. For more information, see Project References.

You should avoid adding file references to outputs of another project in the same solution, because doing so may cause compilation errors. Instead, use the Projects tab of the Add Reference dialog box to create project-to-project references. This makes team development easier, by allowing for better management of the class libraries you create in your projects. For more information, see Troubleshooting Broken References.

If you want to add a reference to a registered COM DLL that contains an internal manifest, make sure that you unregister the DLL first; otherwise, Visual Studio adds the assembly reference as an ActiveX Component rather than as a native DLL.

You can also add Web references using the Add Web Reference dialog box. For more information, see How to: Add and Remove Web References.

To display an assembly in the Add Reference dialog box

  • Move or copy the assembly to one of the following locations:

    • The current project directory (you can find these assemblies using the Browse tab).

    • Other project directories within the same solution (you can find these assemblies using the Projects tab).

    • The Public Assemblies folder: Program Files\Microsoft Visual Studio .NET\Common7\IDE\Public Assemblies; (you can find these assemblies on the .NET tab).

  • Set a reference path to the directory containing the assembly using the Reference Paths Dialog Box (Visual Basic) or the Reference Paths Page, Project Designer (C#, J#).

  • Set a registry key that specifies the location of assemblies to display:

    Add one of the following registry keys, where <AssemblyLocation> is the directory of the assemblies that you want to appear in the Add Reference dialog box, for example, C:\MyAssemblies\.

    [HKEY_CURRENT_USER\SOFTWARE\Microsoft\.NETFramework\<version>\AssemblyFoldersEx\MyAssemblies]@="<AssemblyLocation>"

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\<version>\AssemblyFoldersEx\MyAssemblies]@="<AssemblyLocation>"

    NoteNote

    Creating the registry key under the HKEY_LOCAL_MACHINE node allows all users to see the assemblies in the specified location in the Add Reference dialog box. Creating the registry key under the HKEY_CURRENT_USER node only affects the setting for the current user.

    Invoke the Add Reference dialog box again; the assemblies should appear on the .NET tab. If they do not, ensure that the assemblies exist in the specified <AssemblyLocation> directory, then restart Visual Studio and try again.

To add a reference in Visual Basic

  1. In Solution Explorer, double-click the My Project node for the project.

  2. In the Project Designer, click the References tab.

  3. Click the Add button to open the Add Reference dialog box.

  4. In the Add Reference dialog box, select the tab indicating the type of component you want to reference.

  5. Select the components you want to reference, then click OK.

    NoteTip

    You can select multiple components by holding down the CTRL key, provided the components are all on the same tab.

To add a reference in Visual C# or Visual J#

  1. In Solution Explorer, right-click on the project node and click Add Reference.

  2. In the Add Reference dialog box, select the tab indicating the type of component you want to reference.

  3. Select the components you want to reference, then click OK.

    NoteTip

    You can select multiple components by holding down the CTRL key, provided the components are all on the same tab.

To remove a reference in Visual Basic

  1. In Solution Explorer, double-click the My Project node for the project.

  2. In the Project Designer, click the References tab.

  3. In the References list, select the reference you wish to remove.

  4. Click the Remove button.

    NoteTip

    You can also check your project for unused references and remove all of them at once. For more information, see How to: Remove Unused References (Visual Basic).

To remove a reference in Visual C# or Visual J#

  1. In Solution Explorer, open the References node under the project node.

  2. Right-click on a reference and click Remove.

    NoteTip

    You can also check your project for unused references and remove all of them at once. For more information, see How to: Remove Unused References (Visual Basic).

To set a reference path in Visual Basic

  1. In Solution Explorer, double-click the My Project node for the project.

  2. In the Project Designer, click the References tab.

  3. Click the Reference Paths button.

  4. In the Reference Paths dialog box, in the Folder: field, enter the full path to the folder that contains the components.

  5. Click the Add Folder button, then click OK.

    NoteNote

    Only the specified folder will be searched each time the Add Reference dialog box is opened; subfolders will not be searched. You must add a separate path for each subdirectory to be searched.

To set a reference path in Visual C# or Visual J#

  1. In Solution Explorer, right-click on the project node and click Properties.

  2. In the Project Designer, click the Reference Paths tab.

  3. In the Folder: field, enter the full path to the folder that contains the components.

  4. Click the Add Folder button, then click OK.

    NoteNote

    Only the specified folder will be searched each time the Add Reference dialog box is opened; subfolders will not be searched. You must add a separate path for each subdirectory to be searched.

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft