Visual Studio Tip #8: Adding existing files with Show All Files

Sometimes instead of adding a new file to your project, you need to reuse an existing file. That might be code, but often it is some sort of content like a bitmap or an xml document.

I’ve seen new users copy that item into their project directory and then look at their project in Visual Studio and say “Um, where’s my file?”

For most project types the folder is not the project. The project file (*.csproj, *.vbproj, etc) contains a list of all the files in the project which usually just happen to live in the same folder structure. Visual Studio manages the project file so you need to tell Visual Studio to add that file to the project.

The formal way to add a file that already exists is the Add Existing Item menu.

add-existing-item-menu

But often I’ll use the Show All Files feature instead.

There is a button in the Solution Explorer called “Show All Files”. (If the button isn't there, make sure you have the project selected and not the solution.)

show-all-files-button

Click that button and Visual Studio will that will show all the files in the project folder and not just those that are included in the project. Files and folders that are not currently part of the project will have their icons shown with dotted outlines

show-all-files-enabled

Then you can just right-click the file you want to include, and select Include in Project. That will promote the file into your project.

Include-in-project-menu

You can then disable “Show All Files” to get back to the regular view.

project includes existing file

 

This post is part of a series of Visual Studio tips. The first post in the series contains the whole list.

(next tip: Edit directly in the Diff tool)