Http://msdn2.microsoft.com/zh-cn/library/wkze6zky (vs.80). aspx
Visual Studio How to: add or remove references in Visual Studio
Note: |
The process of setting reference paths for Visual C # and Visual J # projects is slightly different. In the Visual Basic Project, click "Reference Path" to bring up the "add reference" dialog box. In the Visual C # Or Visual J # project, the "Project Designer"> "Reference Path" Page (C #, J #) is used #). For more information, see How to: Set the reference path (C #, J #). |
ToProgramTo use a component, you must first Add a reference to the component. Visual Studio provides five options in the "add reference" dialog box:
". Net": Lists All. NET Framework components that can be referenced.
"Com": Lists All COM components that can be referenced.
"Project": lists all reusable components created in a local project.
"Browse": Used to browse and find components in the file system.
Recent: lists the components recently added to the project on the computer.
The add reference dialog box only lists the assemblies in the Public Assemblies folder (Program Files \ Microsoft Visual Studio. Net \ common7 \ ide \ public assemblies. You can copy your own assembly to the Public Assemblies folder or directly browse these assembly. Note that reference cannot be added from the Global Assembly Cache (GAC) because it is completely part of the runtime environment.
If an application contains a reference to a custom component registered in GACCopy localThe component will not be deployed or copied with the application. For more information, see project reference.
Avoid adding file references to the output of another project in the same solution, because this may cause compilation errors. You should use the "project" option card in the "add reference" dialog box to create a reference from a project to a project. In this way, you can better manage the class libraries created in the project to facilitate team development. For more information, see troubleshooting invalid references.
If you want to add a reference to a registered com DLL that contains an internal list, ensure that the DLL is deregistered first; otherwise, Visual Studio adds the Assembly reference as an ActiveX component rather than a local DLL.
You can also use the "add web reference" dialog box to add a web reference. For more information, see How to: add and remove web references.
The "add reference" dialog box displays the Assembly
Move or copy an assembly to one of the following locations:
The current project directory (you can find these assemblies on the Browse tab ).
Other project directories in the same solution (you can find these assemblies on the projects tab ).
Public assemblies Folder: Program Files \ Microsoft Visual Studio. Net \ common7 \ ide \ public assemblies; (you can find these sets on the. NET tab ).
-
Use the Reference Path dialog box (Visual Basic) or the project designer-> reference path page (C #, J #) to set a reference path to include the assembly.
Set the registry key for the location of the assembly to be displayed:
Add one of the following registry items, where<Assembly location>Is the Assembly directory to be displayed in the "add reference" dialog box, such as c: \ myassemblies \.
[HKEY_CURRENT_USER \ Software \ Microsoft \. netframework \<Version>\ Assemblyfoldersex \ myassemblies] @ ="<Assembly location>"
[HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \. netframework \<Version>\ Assemblyfoldersex \ myassemblies] @ ="<Assembly location>"
Note: |
After you create a registry key under the HKEY_LOCAL_MACHINE node, all users can view these sets at the specified position in the "add reference" dialog box. If you create a registry key under the HKEY_CURRENT_USER node, the setting of the current user will only be affected. |
Call the "add reference" dialog box again. These assemblies should be displayed on the ". Net" tab. If not displayed, make sure these assemblies exist in the specified<Assembly location>Directory, and then restart Visual Studio and try again.
Add reference in Visual Basic
In Solution Explorer, double-click the my projects node of the project.
In project designer, click the reference tab.
Click Add to open the Add reference dialog box.
In the Add reference dialog box, select the tab that indicates the type of the component to be referenced.
Select the component to be referenced and click OK ".
Prompt |
If all components to be referenced are on the same tab, press Ctrl to select multiple components at the same time. |
Add reference in Visual C # Or Visual J #
In Solution Explorer, right-click the project node and click Add reference ".
In the Add reference dialog box, select the tab that indicates the type of the component to be referenced.
Select the component to be referenced and click OK ".
Prompt |
If all components to be referenced are on the same tab, press Ctrl to select multiple components at the same time. |
Remove references in Visual Basic
In Solution Explorer, double-click the my projects node of the project.
In project designer, click the reference tab.
In the reference list, select the reference you want to remove.
Click "Remove.
Prompt |
You can also find unused references in the project and remove them all at once. For more information, see How to: Remove unused references (Visual Basic ). |
Remove references in Visual C # Or Visual J #
In Solution Explorer, open the reference node under the project node.
Right-click a reference and click "Remove ".
Prompt |
You can also find unused references in the project and remove them all at once. For more information, see How to: Remove unused references (Visual Basic ). |
Set Reference Path in Visual Basic
In Solution Explorer, double-click the my projects node of the project.
In project designer, click the reference tab.
Click reference path.
In the "Reference Path" dialog box, enter the complete path of the folder containing components in the "folder:" field.
Click Add folder, and then click OK ".
Note: |
Each time the "add reference" dialog box is opened, only the specified folder is searched, and no subfolders are searched. You must add a separate path for each subdirectory to be searched. |
Set the Reference Path in Visual C # Or Visual J #
In Solution Explorer, right-click the project node and click Properties ".
In the project designer, click the Reference Path tab.
In the "folder" field, enter the complete path of the folder containing components.
Click Add folder, and then click OK ".
Note: |
Each time the "add reference" dialog box is opened, only the specified folder is searched, and no subfolders are searched. You must add a separate path for each subdirectory to be searched. |