<p>I have a free standing set of files not affiliated with any C# project at all that reside in a complicated nested directory structure.</p>

<p>I want to add them in that format to a different directory in an ASP.NET web application I am working on; while retaining the same structure. So, I copied the folder into the target location of my project and I tried to “add existing  item” only to lose the previous folder hierarchy.</p>

<p>Usually I have re-created the directories by hand, copied across on a one-to-one basis, and then added existing items. There are simply too many directories/items in this case.</p>

<p>So how do you add existing directories and files in Visual Studio 2008?</p>

[{'answer_id': 57778, 'author': 'Darren Kopp', 'author_id': 77, 'author_profile': 'https://Stackoverflow.com/users/77', 'pm_score': 11, 'selected': True, 'text': "<p>Drag the files / folders from Windows Explorer into the Solution Explorer. It will add them all. Note this doesn't work if Visual Studio is in Administrator Mode, because Windows Explorer is a User Mode process.</p>\n"}, {'answer_id': 57788, 'author': 'Brannon', 'author_id': 5745, 'author_profile': 'https://Stackoverflow.com/users/5745', 'pm_score': 9, 'selected': False, 'text': '<p>Enable <em>"Show All Files"</em> for the specific project (you might need to hit "Refresh" to see them)**.  </p>\n\n<p>The folders/files that are not part of your project <em>appear slightly "lighter"</em> in the project tree.  </p>\n\n<p><em>Right click</em> the folders/files you want to add and click <em>"Include In Project"</em>. It will recursively add folders/files to the project.</p>\n\n<p>** These buttons are located on the mini Solution Explorer toolbar.</p>\n\n<p>** Make sure you are NOT in debug mode.</p>\n'}, {'answer_id': 8201550, 'author': 'nader', 'author_id': 1056347, 'author_profile': 'https://Stackoverflow.com/users/1056347', 'pm_score': 3, 'selected': False, 'text': '<p>You need to put your directory structure in your project directory. And then click "Show All Files" icon in the top of Solution Explorer toolbox. After that, the added directory will be shown up. You will then need to select this directory, right click, and choose "Include in Project."</p>\n'}, {'answer_id': 9202193, 'author': 'Don Rule', 'author_id': 1198339, 'author_profile': 'https://Stackoverflow.com/users/1198339', 'pm_score': 5, 'selected': False, 'text': '<p>I didn\'t immediately understand this based upon these descriptions but here is what I finally stumbled on:</p>\n\n<ol>\n<li>Turn on "Show All Files" - there is an icon on the Solution Explorer toolbar</li>\n<li>Using Windows Explorer (not solution explorer), move your files into the directory structure where you want them to reside</li>\n<li>Click "Refresh" also on the Solution Explorer toolbar</li>\n<li>The files that you\'ve moved should be visible "ghosted" in the Solution Explorer tree structure where you\'ve placed them</li>\n<li>Right click on your ghosted files or folders and click "Include in Project". All the contents of a folder will be included</li>\n</ol>\n'}, {'answer_id': 11420998, 'author': 'Tom', 'author_id': 798326, 'author_profile': 'https://Stackoverflow.com/users/798326', 'pm_score': 7, 'selected': False, 'text': '<p>In Solution Explorer:</p>\n\n<ol>\n<li>Click <em>Show All Files</em> (second icon from the left at the top of Solution Explorer).</li>\n<li>Locate the folder you want to add.</li>\n<li>Right-click and select <em>"Include in Project"</em></li>\n</ol>\n\n<p>I use this to install add-ons like HTML editors and third-party file browsers.</p>\n'}, {'answer_id': 13624351, 'author': 'Boris_P_', 'author_id': 1395598, 'author_profile': 'https://Stackoverflow.com/users/1395598', 'pm_score': 0, 'selected': False, 'text': '<p>In Windows 7 you could do the following:</p>\n\n<p>Right click on your project and select "Add->Existing Item". In the dialog which appears, browse to the root of the directory you want to add. In the upper right corner you have a search box. Type <code>*.cs</code> or <code>*.cpp</code>, whatever the type of files you want to add. After the search finishes, select all files, click Add and wait for a while...</p>\n'}, {'answer_id': 24923200, 'author': 'ILIA BROUDNO', 'author_id': 788301, 'author_profile': 'https://Stackoverflow.com/users/788301', 'pm_score': 5, 'selected': False, 'text': '<p>I just want to point out that two of the solutions offered previously,</p>\n\n<ul>\n<li>Drag and drop from Windows Explorer</li>\n<li><em>Show All Files</em> and then include in project.</li>\n</ul>\n\n<p>do not do what the question asked for:</p>\n\n<p>Include in project <em>while preserving the directory structure</em>.</p>\n\n<p>At least not in my case (C++/CLI project Visual Studio 2013 on Windows&nbsp;7).</p>\n\n<p>In Visual Studio, once you are back in the normal view (not <em>Show All Files</em>), the files you added are all listed at the top level of the project.</p>\n\n<p>Yes, on disk they still reside where they were, but in Solution Explorer they are loose.</p>\n\n<p>I did not find a way around it except recreating the directory structure in Solution Explorer and then doing <em>Add Existing Items</em> at the right location.</p>\n'}, {'answer_id': 30772845, 'author': 'Bjego', 'author_id': 3337035, 'author_profile': 'https://Stackoverflow.com/users/3337035', 'pm_score': 3, 'selected': False, 'text': '<p>You can change your project XML to add existing subfolders and structures automatically into your project like "node_modules" from NPM:</p>\n\n<p>This is for older MSBuild / Visual Studio versions</p>\n\n<pre class="lang-xml prettyprint-override"><code>&lt;ItemGroup&gt;\n   &lt;Item Include="$([System.IO.Directory]::GetFiles(&amp;quot;$(MSBuildProjectDirectory)\\node_modules&amp;quot;,&amp;quot;*&amp;quot;,SearchOption.AllDirectories))"&gt;&lt;/Item&gt;\n&lt;/ItemGroup&gt;\n</code></pre>\n\n<p>For the current MSBuild / Visual Studio versions:</p>\n\n<p>Just put it in the nodes of the xml:</p>\n\n<pre class="lang-xml prettyprint-override"><code>&lt;Project&gt;\n&lt;/Project&gt;\n</code></pre>\n\n<p>In this case just change $(MSBuildProjectDirectory)\\node_modules to your folder name.</p>\n'}, {'answer_id': 34569289, 'author': 'kungfooman', 'author_id': 1952626, 'author_profile': 'https://Stackoverflow.com/users/1952626', 'pm_score': -1, 'selected': False, 'text': "<p>It's annoying that Visual Studio doesn't support this natively, but CMake could generate the Visual Studio project as a work around.</p>\n\n<p>Other than that, just use Qt Creator. It can then export a Visual Studio project.</p>\n"}, {'answer_id': 38562223, 'author': 'Marvin Glenn Lacuna', 'author_id': 2705829, 'author_profile': 'https://Stackoverflow.com/users/2705829', 'pm_score': 4, 'selected': False, 'text': '<p>Below is the icon for the \'<strong>Show All Files</strong>\', just for easy reference. </p>\n\n<p><a href="https://i.stack.imgur.com/iELY6.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iELY6.jpg" alt="Enter image description here"></a></p>\n'}, {'answer_id': 38730101, 'author': 'Nick', 'author_id': 594058, 'author_profile': 'https://Stackoverflow.com/users/594058', 'pm_score': 1, 'selected': False, 'text': '<p>What worked for me was to drag the folder into Visual Studio, then right click the folder and select "Open Folder in File Explorer". Then select all and drag them into the folder in Visual Studio.</p>\n'}, {'answer_id': 39918503, 'author': 'Jason Kester', 'author_id': 27214, 'author_profile': 'https://Stackoverflow.com/users/27214', 'pm_score': 0, 'selected': False, 'text': "<p>The cleanest way that I've found to do this is to create a new Class Library project in the target folder, and redirect all of its build output elsewhere.  It still leaves a .csproj file sitting in that folder, but it does let you see it in Visual Studio and pick which files to include in your project.</p>\n"}, {'answer_id': 41642461, 'author': 'Yatrix', 'author_id': 850749, 'author_profile': 'https://Stackoverflow.com/users/850749', 'pm_score': 2, 'selected': False, 'text': '<p>A neat trick I discovered is that if you go to "Add existing...", you can drag the folder from the open dialog to your solution.</p>\n\n<p>I have my Visual Studio to open in Admin Mode automatically, so this was a good workaround for me as I didn\'t want to have to undo that just to get this to work.</p>\n'}, {'answer_id': 42975811, 'author': 'Naren', 'author_id': 2256349, 'author_profile': 'https://Stackoverflow.com/users/2256349', 'pm_score': 2, 'selected': False, 'text': '<p>At last, Visual Studio 2017 allows the user to import an entire directory with a single click. Visual&nbsp;Studio&nbsp;2017 has a new functionality <strong>"Open Folder</strong>" that allows opening the entire folder, even without the need to save it as solution. The source code can be imported using the following methods.</p>\n\n<ol>\n<li>Menu <em>File</em> → <em>Open</em> → *Folder (<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>O</kbd>)</li>\n<li><code>devenv.exe  &lt;source folder&gt;</code></li>\n</ol>\n\n<p>It even supports building and debugging CMake projects.</p>\n\n<p><em><a href="https://blogs.msdn.microsoft.com/vcblog/2016/10/05/bring-your-c-codebase-to-visual-studio-with-open-folder/" rel="nofollow noreferrer">Bring your C++ codebase to Visual Studio with “Open Folder”</a></em></p>\n'}, {'answer_id': 43672798, 'author': 'Willy David Jr', 'author_id': 6542896, 'author_profile': 'https://Stackoverflow.com/users/6542896', 'pm_score': 3, 'selected': False, 'text': '<p>This is what I do:</p>\n\n<ol>\n<li>Right click on solution -> Add -> Existing Website...</li>\n<li>Choose the folder where your website is. Just the root folder of the site.</li>\n</ol>\n\n<p>Then everything will be added on your solution from folders to files, and files inside those folders.</p>\n'}, {'answer_id': 50123040, 'author': 'Manoj Kalluri', 'author_id': 6055570, 'author_profile': 'https://Stackoverflow.com/users/6055570', 'pm_score': 4, 'selected': False, 'text': '<p><a href="https://i.stack.imgur.com/s7cdg.png" rel="noreferrer"><img src="https://i.stack.imgur.com/s7cdg.png" alt="Enter image description here"></a></p>\n\n<p>Click above in the red circle. Your folder will appear in Solution Explorer.</p>\n\n<p>Right click on your folder -> <em>Include in project</em>.</p>\n'}, {'answer_id': 55517956, 'author': 'Yann Duran', 'author_id': 281489, 'author_profile': 'https://Stackoverflow.com/users/281489', 'pm_score': 2, 'selected': False, 'text': '<p>There is now an open-source extension in the Marketplace that seems to do what the OP was asking for:</p>\n\n<p><a href="https://marketplace.visualstudio.com/items?itemName=CeciliaWiren-CeciliaSHARP.FolderToSolutionFolder" rel="nofollow noreferrer">Folder To Solution Folder</a></p>\n\n<p><a href="https://i.stack.imgur.com/vieVa.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vieVa.gif" alt="folder-to-solution-folder"></a></p>\n\n<p>If it doesn\'t do exactly what you want, the code is available, so you can modify it to suit your scenario.</p>\n\n<p>HTH</p>\n'}, {'answer_id': 64142845, 'author': 'C Post', 'author_id': 13090035, 'author_profile': 'https://Stackoverflow.com/users/13090035', 'pm_score': 0, 'selected': False, 'text': '<p>It has been a while since this was originally posted, but here is an alternative answer.\nIf 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.</p>\n<p><a href="https://i.stack.imgur.com/B3Fy6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B3Fy6.png" alt="folder view" /></a></p>\n<p>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 &quot;add the existing&quot; 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.</p>\n'}]
['https://Stackoverflow.com/questions/57776', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2213/']