150

Is there a way to add existing Folders to a Visual Studio Project so that I do not have to do this file by file?

Edit

To make it clear: I want to add references not copies.

ouflak
  • 2,458
  • 10
  • 44
  • 49
HerpDerpington
  • 3,751
  • 4
  • 27
  • 43
  • 4
    It seems that it [http://stackoverflow.com/questions/57776/how-to-add-existing-item-an-entire-directory-structure-in-visual-studio](http://stackoverflow.com/questions/57776/how-to-add-existing-item-an-entire-directory-structure-in-visual-studio) is what you are looking for. – Evgeny Timoshenko Nov 17 '13 at 16:36
  • 1
    @johny this would add copies, wouldn't it? – HerpDerpington Nov 17 '13 at 16:43
  • 1
    also you may have a look at this post http://stackoverflow.com/questions/3610845/add-as-link-for-folders-in-visual-studio-projects – Evgeny Timoshenko Nov 17 '13 at 17:04
  • 1
    You might find this question useful which asks how to add a solution folder as a real folder: https://stackoverflow.com/questions/267200/visual-studio-solutions-folder-as-real-folders – Richard Garside Oct 12 '21 at 10:48

16 Answers16

334

If the folder and its contents have already been created and it physically exists under the Project, you can click the Show All Files icon (at the top of the Solution Explorer windows) and then when the folder shows as a dotted icon, right-click it and choose Include In Project and the folder and all its contents are added.

John J Smith
  • 11,435
  • 9
  • 53
  • 72
  • 10
    sounds good but that does not seem to be an option in vs 2019 – Joe Aug 25 '19 at 13:45
  • 6
    However dragging and dropping the folder into the solution from windows explorer worked, – Joe Aug 25 '19 at 13:50
  • 2
    Works great! I have been using vs for some many years but never realize that there is such a useful button. – Bob Sep 19 '19 at 14:02
  • 11
    @Joe, I am using vs 2019 and it still works for me. You are sure you are looking at the correct icon bar? – Bob Jan 02 '20 at 16:14
  • 2
    If the solution has "solution folders" this does not work – Mauricio Gracia Gutierrez Jul 02 '20 at 15:50
  • I am using Visual Studio 2019 and the "Include In Project" button exists but is grayed out when right-clicking on a .cs file. – Aaron Franke Sep 07 '21 at 20:56
  • @AaronFranke, have you run Visual Studio 2019 as an Administrator? It sounds like you don't have permissions. Close VS and reopen as Administrator and then try again. – John J Smith Sep 08 '21 at 11:47
  • The problem was that VS refuses to include an empty file in the project. When I wrote some C# code in the file then it let me include it. – Aaron Franke Sep 08 '21 at 17:14
  • For what it's worth, I am using VS 2019 Community, and this technique works exactly as described. One fine point that seems to be omitted is that you can click the "Show All Files" button again to hide the files that are present, but are only infrastructure, such as LeadLife_Database_Objects.dbmdl, LeadLife_Database_Objects.jfm, LeadLife_Database_Objects.sqlproj, and LeadLife_Database_Objects.sqlproj.user in the case of the project that brought me to this page. – David A. Gray Nov 03 '21 at 20:59
  • would have been nice if the right click on a folder in project gave and Add Existing Folder option rather than Add "Existing Item" which doesn't allow folder add.. Nevertheless, the route suggested worked for me. thank you – MikeDev Aug 05 '22 at 11:29
99

VS 2019

Click on the 'Show All Files' icon at the top of Solution Explorer window.

'Show All Files' icon

Then the folders/files of the selected project will be displayed as dotted icons. You can right click any of them and select include in project to include them in the project.

For solution folders, click the 'Show All Files' icon then first exclude the desired folders/files and then include them.

DevLoverUmar
  • 11,809
  • 11
  • 68
  • 98
  • 3
    Of the different ways I've tried to add files and folder, this is the only way that seems to work without any fuss – Microbob Sep 19 '20 at 21:54
  • 1
    I've done this in previous versions of VS, too. For some reason, the "Show All Files" icon wasn't showing up for me in 2019, though. It took some fiddling with the Solution Explorer bar sizing for it to show up. IDK what it even took for it to appear, it just all of a sudden was there. – computercarguy Nov 02 '20 at 17:44
  • 1
    Great that there is this workaround but disappointing that add existing item violates the principle of least surprise. – Paul McCarthy Jan 08 '21 at 14:00
  • 1
    I had a situation where I couldn't see the include or exclude in folder options. They came back as soon as I rebooted VS2019. Thanks! – JWP Mar 01 '21 at 04:55
  • 1
    So many years I have been using VS, and I am just now using that feature for the first time. Wow. – Yan Brunet Jul 12 '21 at 14:55
  • I'm using VS2019 Professional (Version 16.11.22), and clicking this button sometimes doesn't have any effects. – Jiang Dec 21 '22 at 05:45
20

@Mark s answer is good, but if there are hundreds or thousands of files it will be quite cumbersome to add all of them. Plus, it does not provision for new files.

There is another method using the .csproj file. I have used this to add content that is part of a submodule that does not have a .csproj file of its own.

Note that I have used the <Content /> tag, as I did not need any of the linked content during compilation.

<ItemGroup>
  <Content Include="..\my\submodule\directory\**" Link="Directory\In\Main\Project\%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
The Thirsty Ape
  • 983
  • 3
  • 16
  • 31
18

You could open Add Existing Item dialog, select a bunch of files, click on Add's button drop-down menu and choose Add as a link. It will add files as references and won't copy them.

Evgeny Timoshenko
  • 3,119
  • 5
  • 33
  • 53
16

You can drag and drop the entire folder. If all files don't show you can repeat the drag'n'drop procedure for subfolders.

kburnik
  • 359
  • 3
  • 6
  • 2
    You can also copy external folders in file explorer and paste it in visual studio project explorer. – Zeni Apr 12 '16 at 06:54
  • this should be the correct answer, as the other answer doesn't entail how you would create the folder, if it is already there it will complain about there already being a folder there. – thekevshow Nov 03 '16 at 19:10
12

This answer applies to and , the most up to date versions at the time the question was asked and this answer was given. More recent versions have improved their handling and have other answers here. For someone using the old versions, this answer still applies.


Answer:

I don't think there is, but if you have all the files in one folder, you can add multiple files in one go. Just mark them all in the add file dialog.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
8
  1. right click the project, and choose "New Solution Explorer view", a window pops up.
  2. and then form the toolbar of the new window ("solution explore window"), you click the "Show All Files" icon.
  3. then include the folders of interest into your project...
Jim L
  • 2,297
  • 17
  • 20
user9352585
  • 81
  • 1
  • 1
6

If you're working in VS 2019 Community Edition, I find that you can:

  1. Open the parent folder of whatever folder you're trying to add in windows explorer
  2. Right-click and copy that folder
  3. Go to the solution explorer in visual studio
  4. Right-click then paste the folder wherever you want to in the solution tree
elersong
  • 756
  • 4
  • 12
  • 29
Loran Hayden
  • 61
  • 1
  • 1
4

In Visual Studio 2019 I could not drag and drop from file explorer or 'Show All Files' and then add them. Instead, while in File Explorer, right click and choose copy, then click on the location within Visual Studio 2019 and right click and choose paste. All of the files in the folder and subfolders will be added.

th3morg
  • 4,321
  • 1
  • 32
  • 45
3

kburnik's answer worked well for my use-case, but for anyone who needs a scriptable way to bring a lot of folder hierarchy back, you can modify the .*proj file to re-include the folders and files:

<?xml version="1.0" encoding="utf-8"?>
<Project ...>
  ...
  <ItemGroup>
    <Compile Include="Path\To\File1.ext" />
    <Compile Include="Path\To\File2.ext" />
    ...
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Only\Empty\Folders\Need\To\Be\Listed\Here" />
    ...
  </ItemGroup>

Just make sure that before you do this, you save the .*proj file if it's still open in Visual Studio.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Mark
  • 31
  • 1
  • 3
3

You can drag and drop the entire folder or missing folders in the project.

rsmdh
  • 128
  • 1
  • 2
  • 12
2

If the folder and its contents have already been created and it physically exists under the Project then click on view over the project enter image description here then you can see all folders and files and you just need to copy files and click on solution in the same folder view and paste all in there

2

It has been a while since this was originally posted, but here is an alternative answer for a solution folder that is NOT inside of a project. If you only care to be able to look at the physical files from inside visual studio and do not necessarily require to see them in the solution explorer default view, then click on the switch view button and choose the folder view and any physical directory/directories that are under your solution root folder will appear here even if they do not appear in the solution explorer default view.

folder view

If however, you want to add a folder tree that isn't too large as a virtual solution directory/directories to match your existing tree structure, do that and and then "add the existing" physical files to the virtual directory/directories. If the physical directory exists in your solution directory it will not copy the files - it will link directly to the physical files but they will appear as part of the solution virtual directories.

C Post
  • 46
  • 4
  • 1
    Before you paste this in even more locations, please take the time to read [Is it acceptable to add a duplicate answer to several questions?](https://meta.stackexchange.com/questions/104227/is-it-acceptable-to-add-a-duplicate-answer-to-several-questions). – fcdt Sep 30 '20 at 18:10
1

Possibly some of you weren't born when this question was first asked!

If you have external directories, you can add them to a solution as a "website". This gives you all the benefits of being able to search through the solution and easily add new files to the website. It doesn't have to contain html, it can be a set of word documents, for example. So for example, I've got a single solution that contains every sql and oracle query I've ever worked on or harvested from a co-worker. Why? Because it's difficult to keep up with similar sounding field and table names across different databases when you're trying to write a new query.

This also works with TFS.

Todd Harvey
  • 309
  • 3
  • 4
0

Check whether that folder is inside project folder or not, if yes:

  1. click Show All files in solution explorer.

  2. now you can see folder name in solution explorer. right click the folder -> Include In Project.

  3. If the folder out of project please copy it into the project directory in the place where we want it.

Gaurav Jeswani
  • 4,410
  • 6
  • 26
  • 47
0

If your folder exist in another project but you want to add the folder and its content to another project just -- go to the folder location -- Copy your desired folder -- go back to your current project -- right click on the project and then just paste it.

folder will be added in your current project. you may need to fix the namspace of the copying file.