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?

JMK
  • 27,273
  • 52
  • 163
  • 280
  • Did you try clicking Add Folder and name it just as your directory on disk? – rene Sep 30 '12 at 17:29
  • 9
    Tried drag and droping the folder from Windows Explorer onto your Visual Studio solution window? Source: http://stackoverflow.com/questions/392473/how-do-i-add-an-existing-directory-tree-to-a-project-in-visual-studio – Chris Oct 01 '12 at 09:19
  • @Chris You should really post this as an answer, because..er...it is haha – JMK Jul 26 '13 at 17:57
  • @Johnny_D The answer with 7 votes was more helpful though. – JMK Oct 28 '13 at 08:15
  • It's up to you. I followed one with 50 votes. – Johnny_D Oct 28 '13 at 08:22

7 Answers7

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

mitaka
  • 2,159
  • 1
  • 30
  • 30
Radenko Zec
  • 7,659
  • 6
  • 35
  • 39
  • 1
    I can not find this button. Is this, because I have only the Express edition? – Marcel Feb 09 '13 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 06 '13 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 – Radenko Zec Mar 07 '13 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 '13 at 21:40
  • 1
    @rhaag71 in my case it copy the folder with a new name, not just include it in the project – Juan Antonio Orozco Mar 18 '13 at 16:33
  • 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 04 '13 at 15:13
  • The button exists, but if you are debugging a solution, it wont appear! – Zocket Jan 24 '14 at 20:39
  • Wow... all these years with never a clue that I could do this :-D – Riegardt Steyn Mar 26 '14 at 10:02
  • VS2012 - it doesn't work if you drag folder to the solution it self - it works obly if you drag it inside of a project :( – Yuriy Anisimov Jul 18 '15 at 13:58
  • How do I go back to not showing all items? It's kind of annoying that this button seems to be a one way ticket. – ajeh Jan 18 '17 at 15:08
83

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

Source here

or simply copy & paste into solution explorer.

Community
  • 1
  • 1
Chris
  • 5,516
  • 1
  • 26
  • 30
  • drag and drop looses folder structure (VS12 Express) – Opsenas Jun 09 '15 at 09:52
  • 1
    @Chris: There is no drag and drop from explorer into solution explorer. What are you talking about? – ajeh Jan 18 '17 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 '17 at 09: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"

skrrgwasme
  • 9,358
  • 11
  • 54
  • 84
Admiral
  • 41
  • 1
  • 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 '14 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 '14 at 00: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.

Makyen
  • 31,849
  • 12
  • 86
  • 121
Jabare Mitchell
  • 141
  • 1
  • 7
  • 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... – Jabare Mitchell Dec 23 '14 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

N_E
  • 743
  • 10
  • 16
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.)

Daetrin
  • 11
  • 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 '15 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 '15 at 00:50