|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|
Adding and Removing References
In order to use a component in your application, you must first add a reference to it. Visual Studio .NET provides three options on 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 in local projects.
You can also add Web references in the Add Web Reference dialog box. For more information, see Adding and Removing Web References.
Note 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 References 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.
To add a reference
- In Solution Explorer, expand the project node you want to add a reference to.
- Right-click the References node for the project and select Add Reference from the shortcut menu.
- To add a reference to a component or components, do the following:
- In the Add Reference dialog box, select the tab indicating the type of component you want to reference. For more information, see Add Reference Dialog Box.
- In the top pane, select the component you want to reference, and then click the Select button.
Tip If the component you are looking for is not in the list, you may locate it using the Browse button.
The component you referenced appears in the SelectedComponents pane of the dialog box. Repeat Step b for each additional component you wish to add.
- Click OK when you have added references to all the components you need.
Selected references will appear under the References node of the project.
To remove a reference
- In Solution Explorer, right-click the reference in the References node, and select Remove from the shortcut menu.
By default, the Add References dialog box only lists assemblies that are in the Public Assemblies folder (Program Files\Microsoft Visual Studio .NET\Common7\IDE\Public Assemblies) or in the Global Assembly cache. You can add your own assemblies to the list by adding a registry key to specify their location.
To add assemblies to the Add References dialog box
- In Windows, click the Start button, click Run, then type regedit to open the Registry Editor.
- Select the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.0\AssemblyFolders
- On the Edit menu, point to New, then click Key.
- Enter a name for the key (for example, MyAssemblies).
- Select the (Default) value for the key that you just added.
- On the Edit menu, choose Modify.
- In the Edit String dialog box, select the Value data field and enter the full path to the folder where your assemblies are located.
Note Only the specified folder will be searched each time the Add References dialog box is opened; subfolders will not be searched. You must add a separate key for each subdirectory to be searched.