Share via


Adding and Removing Files from Projects

Home Page (Projects)OverviewsHow Do I... TopicsNMAKE Reference

When you add a file to a project, you add the file to all configurations for that project. For instance, if you have a project named MyProject, with Debug and Release configurations, adding a file adds it to both those project configurations.

If you add files from directories on a different drive than the project, Visual C++ uses absolute paths in the filenames for those files in the project's .dsp file. Because of the absolute paths, it is difficult to share the project (.dsp) file. Other developers in your group may have other drive names.

To support sharing files outside the project directory, you can use the Persist As field in the source file's property page. In the Persist As field, put in a replacement path for the file that will be persisted ("preserved") in the project file.

For example:

  1. Add a file, c:\basefiles\mybase.cpp, to your project, where your project is located at c:\myproject\project1.

  2. Use the Persist As field in either of two ways:

    • In the Persist As field, change the string "c:\basefiles\mybase.cpp" to "..\..\basefiles\mybase.cpp."

      This requires all users of the project to maintain the same directory structure that you use for the project.

    -or-

    • Define an environmental variable, such as "BASEFILES," that contains "c:\basefiles" on the user's machine, and change the string in the Persist As field from "c:\basefiles\mybase.cpp" to "$(BASEFILES)\mybase.cpp."

Note: The NMAKE utility requires that you use upper case for the environment variable names.

What do you want to do?

Add files to a project

Move or copy files from one project to another

Remove files from a project

To add files to a project

  1. Open the project to which you want to add files.

  2. On the Project menu, click Add To Project, and then click Files.

  3. In the Files of type box, specify the type of files to add.

  4. Select one or more files.

  5. Click OK.

Note   You can also use the shortcut menu from FileView to add files more quickly.

To move or copy files from one workspace to another

  1. From the FileView pane, select the files that you want to move or copy.

  2. On the Edit menu, click Cut if you want to move the files, or Copy if you want to copy the files.

  3. Close the current project workspace.

  4. Open the destination project workspace.

  5. Select the project to receive the files.

  6. On the Edit menu, click Paste.

To remove files from a project

  1. From the FileView pane, select the files that you want to remove.

  2. On the Edit menu, click Delete.