Export (0) Print
Expand All

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

  1. In Solution Explorer, expand the project node you want to add a reference to.
  2. Right-click the References node for the project and select Add Reference from the shortcut menu.
  3. To add a reference to a component or components, do the following:
    1. 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.
    2. 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.

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

  1. In Windows, click the Start button, click Run, then type regedit to open the Registry Editor.
  2. Select the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.0\AssemblyFolders
  3. On the Edit menu, point to New, then click Key.
  4. Enter a name for the key (for example, MyAssemblies).
  5. Select the (Default) value for the key that you just added.
  6. On the Edit menu, choose Modify.
  7. 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.

See Also

Troubleshooting Broken References | Referencing Namespaces and Components | Managing Project Web References | Adding New Project Items

Show:
© 2014 Microsoft