107

I want to add an already existing directory to a directory in Solution Explorer, but whenever I right-click on the directory and select Add => Existing Item, I can only add individual files, but not directories.

How do I add an already existing directory to a directory inside a Project inside Solution Explorer?

5
  • Did you try clicking Add Folder and name it just as your directory on disk?
    – rene
    Sep 30, 2012 at 17:29
  • 9
    Tried drag and droping the folder from Windows Explorer onto your Visual Studio solution window? Source: stackoverflow.com/questions/392473/…
    – Chris
    Oct 1, 2012 at 9:19
  • @Chris You should really post this as an answer, because..er...it is haha
    – JMK
    Jul 26, 2013 at 17:57
  • @Johnny_D The answer with 7 votes was more helpful though.
    – JMK
    Oct 28, 2013 at 8:15
  • It's up to you. I followed one with 50 votes.
    – Johnny_D
    Oct 28, 2013 at 8:22

7 Answers 7

178

Click the 'Show all files' button at the top of the Solution Explorer and right click the folder desired and select 'include in project'.

Show All Files button in VS2012 Solution Explorer

10
  • 1
    I can not find this button. Is this, because I have only the Express edition?
    – Marcel
    Feb 9, 2013 at 20:41
  • 2
    As far as I can tell, the "show all files" button no longer exists in VS 2012. PLEASE correct me if I'm wrong, however, as I miss this functionality. EDIT: At least, it doesn't exist for web site projects.
    – Klay
    Mar 6, 2013 at 15:43
  • 1
    Hi Klay. As I can see "show all files" button exists in VS2012 however it's not exist in web site project. My recommendation for you is: Try not to use web site project if you need this functionality Mar 7, 2013 at 17:53
  • 2
    I know this is a little late, but if your directory (folder) is already in place on the filesystem and you want to add it to your project (as this is stated more simply in the comments above).. just open up the file explorer (like normal.. open folder in Windows) and the drag the folder and drop it on the desired folder in your solution explorer pane.. job done! I just did this and it works as I do not either have the 'show all files', and I still desire to use 'Web site project' for my project.
    – rhaag71
    Mar 12, 2013 at 21:40
  • 16
    For those having trouble finding the button, note that the buttons at the top of Solution Explorer change depending on what's selected (in VS2012 at least). Make sure you have your project selected.
    – Jon-Eric
    Apr 4, 2013 at 15:13
83

Drag and drop the folder from Windows Explorer onto your Visual Studio solution window :)

Source here

or simply copy & paste into solution explorer.

3
  • drag and drop looses folder structure (VS12 Express)
    – Opsenas
    Jun 9, 2015 at 9:52
  • 1
    @Chris: There is no drag and drop from explorer into solution explorer. What are you talking about?
    – ajeh
    Jan 18, 2017 at 15:04
  • @ajeh If you have an explorer window open next to visual studio, select a file from explorer then drag and drop into the visual studio Solution Explorer window
    – Chris
    Jan 19, 2017 at 9:07
10

VS 2012 seems to distinguish between 'Solution Folders', which are only folders containing either other solution folders, or containing project folders. The drag-and-drop works (with my settings) only for the project folders, and no for the solution folders. If I add a new solution folder, nothing happens on the machine. If I drag-and-drop a machine folder to the main Solution, it refuses to accept it. If I drag-and-drop the folder to a Solution Folder, I get an error message saying this cannot be done.

4

Some other answers are missing an important point: if the folder is not in a project in the solution it is impossible to add the folder

This is the solution:

1) Add a new folder to the sln - it does not care that the folder already exists on the disk because this a virtual folder in the sln

2) Add the file to the folder using "add existing files"

2
  • I have a suggestion for you: avoid making your answer sound like a comment. Your original answer had the phrase "I just had to add a comment...", which to me suggests that it should be a comment instead of an answer. Starting your answer with a line like this may get it flagged as "Not An Answer". It looks to me like your answer really is attempting to answer to the question, so I've edited it to prevent NAA flags.
    – skrrgwasme
    Sep 18, 2014 at 18:50
  • it did answer the question, however as i have been developing for 35 years my English happens to be blunt and to the point Besides this the code never gets its feelings hurt when it does not understand, it just does not work
    – Admiral
    Nov 12, 2014 at 0:19
2

When dealing with a solution level folder that has been removed for some reason, and now needs to be added back, open the .sln file in a text editor like notepad++.

Find your "FolderName" in the section that looks like this...

Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NewFolder1", "NewFolder1", "{73ED84FC-F250-4CCC-B267-34CEB67F2883}" EndProject

Delete from "Project" to "EndProject" ONLY for the specific Project/Folder you're having trouble with.

You may get a message in VS2012 that says your solution has been modified by an external source. Choose the option to "Discard" your changes for the external changes. Lastly, add your solution level folder, and add your project(s) to that folder as existing items, drag/drop them, or copy and paste them, according to your preference.

1
  • I received a down vote, but previous responses, some of which with upvotes, explain that many of the solutions, particularly the one with the checkmark as the answer, won't help someone who's getting the "folder already exists" message when attempting to add a solution folder. I had to find the solution to that very issue myself and I posted it here to help anyone else... Dec 23, 2014 at 15:20
2

For those who had a hunch it could be done but weren't able to do it, NOTE: Drag Folder or Files ONTO the name of the Project Name in Solution Explorer in the least

1

Expand the "Project" item in the menu bar and select "Show All Files". Then locate the folder you wish to add in the Solution Explorer (folders that are not currently included will be light grey with a dotted outline instead of the usual solid icon) right click the desired folder and select "Include in project"

Once finished select "Show All Files" from the Project menu again to return to the regular view.

(This is very similar to Radenko Zec's answer, but does not require the "Show All Files" button to already be present in a toolbar. I would just leave this as a response to his answer, but I don't currently have the reputation to leave comments.)

2
  • I believe you may have just skimmed over the the original post, because it did provide an answer. However I have edited the post to make that answer more clear. I'm not sure why you are informing me of the need to have a higher reputation in order to comment on posts since I explicitly stated that in the answer, as part of the comment explaining that I was leaving a supplementary answer as a new post rather than a comment because of that reputation limit. But thank you for your feedback!
    – Daetrin
    Mar 11, 2015 at 23:14
  • That text is automatically posted whenever an answer is flagged as not being such. Apart from that, the edit makes it more clear.
    – Davidmh
    Mar 12, 2015 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.