Export (0) Print
Expand All

How to: Add Existing Items to a Project 

You can add items you have created to new or existing projects. However, the project determines if items are managed as files or as a links. For more information, see Item Management in Projects.

Caution noteCaution

Before opening an existing project or component, determine the trustworthiness of the code outside of Visual Studio. Opening projects or components in certain Visual Studio designers executes code from that project or component on your local machine in the trusted process of devenv.exe.

You can add any type of existing file from storage to your projects. If you are adding 200 or more files, open Windows Explorer and drag them to your project in Solution Explorer for best system performance.

To add an existing item to a project

  1. In Solution Explorer, select a target project.

  2. On the Project menu, select Add Existing Item.

  3. In the Add Existing Item dialog box, locate and select the project item you want to add.

    NoteNote

    Some items related to XML Web Services and ASP.NET Web applications are located in a virtual directory on the Web server.

  4. Choose Open and view the item in the default editor.

    NoteNote

    You can open some files in a non-default editor. For such files, a drop-down button appears next to the Open button. You can click the drop-down button, select Open With, and choose a non-default editor for your file. For more information, see Open With Dialog Box.

Adding an Existing Item as a Link

If you want to explicitly add an item as a link, you can create links in the following projects:

  • Visual C++ projects and other similar projects support only links, so all of the items in these projects are links. The project does not attach a link indicator (a small arrow) to the item icon in Solution Explorer.

  • Visual Basic projects, Visual C# projects, and other similar projects can accommodate both linked and physical project items. Linked items in these projects display a link indicator attached to the icons of linked project items.

    NoteNote

    Visual Basic Web projects, Visual C# Web projects, and other similar projects do not support links to items.

By linking to the file, you can capture ongoing changes to a source file without having to manually update a copy whenever changes are made. However, if you link to a file that is later deleted when its original project no longer uses it, your link is no longer usable.

To create a link in preference to a physical file

  1. In Solution Explorer, select the target project.

  2. Select the Project menu.

  3. Select Add Existing Item.

  4. In the Add Existing Item dialog box, select the item you want to link.

  5. From the Open button drop-down list, select Add As Link.

    NoteNote

    If the error message, "Cannot add a link to a file that is inside the project tree" appears, you need to create a solution directory for your future solutions by selecting the Create directory for Solution option in the New Project dialog box. For more information, see How to: Create Directories for Solutions.

If you want to ensure that a project that links to files is working with its own copy, you can create a copy and then add it to the project.

To create a separate file in preference to a link

  1. In Windows Explorer, locate the file you want, and then select Copy on the Edit menu.

  2. Locate the target directory and then select Paste on the Edit menu.

  3. In Solution Explorer, select the target project and select Add Existing Item on the Project menu.

  4. In the Add Existing Item dialog box, locate and select the project item you want to add.

  5. Select Open.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft