15

Is it possible to add a folder structure to Solution Items without manually adding each level of the tree?

We have a multi project solution which requires several third-party libraries, at least one of which has a multi-layer tree.

We have a libs folder at the solution root level, alongside all the other projects.

The answers regarding Show Hidden Files, etc. don't work for solution items, only within a project.

Is there any way to get around this?

Do we have to add them folder by folder if we want them at the solution level?

(A similar question has been answered many times regarding Visual Studio projects. However my question is about Visual Studio solutions.)

Community
  • 1
  • 1
Shevek
  • 3,869
  • 5
  • 43
  • 63
  • Solution folders do not map to *actual* folders in the file system. You need to use project-level folders, instead. – Cody Gray - on strike May 10 '11 at 14:45
  • 1
    Why do you want the libs folder to be in a solution? What benifit will that bring to the solution? It should just to compiled DLLs – Burt May 10 '11 at 14:48
  • Why do you want the `libs` folder to be in a solution? What benefit will that bring to the solution? It should just contain compiled DLLs. – Burt May 19 '11 at 14:32
  • Thanks Burt - we did end up not including them in the Solution. The libs are now managed by NuGet and kept in "packages" folder in the solution - hidden to the .sln but under revision control. – Shevek May 19 '11 at 18:18
  • That is exactly the way I would have done it. I learned a lot from looking at the way Open Source projects are organised, they take the same approach as well. – Burt May 20 '11 at 10:28
  • This is not the answer to this question. It should be possible to add a full folder tree to a solution (not to a project) regardless of it being a libs folder or anything else. I would like to know if it is or isn't possible. – fretje May 02 '13 at 16:36
  • No it is not possible – Burt May 03 '13 at 13:36
  • Unusual that a non-answer is selected as the correct answer. – Andrew Jan 26 '20 at 18:57
  • @Andrew erm, there isn't a selected answer?? – Shevek Jan 26 '20 at 22:07
  • @Shevek A mod just deleted the selected answer I guess. – Andrew Jan 26 '20 at 22:17

6 Answers6

6

Solution folders are just logical groupings of items. I don't think they relate to the file structure on your system. That is why you don't see them with a "Show hidden files" sort of functionality. You must right-click the solution, add a new folder, and then right click on the folder to add existing items or nested folders.

Mike Dour
  • 3,616
  • 2
  • 22
  • 24
  • 1
    The good news is you can drag and drop files into a solution folder from windows explorer, but you can't drag and drop folders. – Mike Dour May 10 '11 at 14:49
4

Not quite an answer to the question, but to view folders on the file system within Visual Studio Solution Explorer there is now a way of switching views between the solution and the folders. Here is the button to switch:

Visual Studio Solution Explorer showing mouse hovering over switch button in tool bar

Clicking/tapping on this brings up "Solution Explorer - Views" content showing all available solution files and option for "Folder View":

Solution Explorer Views content showing both solution folder and solution file

Double clicking the "Folder View" shows the folders in the underlying file system:

Solution Explorer Folder View showing folder in the underlying file system

Screen shots taken with Visual Studio 2019 16.10 preview 4, but this has been there for a while now.

Josh Gallagher
  • 5,211
  • 2
  • 33
  • 60
4

I was looking for something similar and came across this thread. I had several data files that I wanted included with my solution but weren't specific to any one project in that solution.

I'm using VS 2019 and discovered they now have "Shared Projects" in C#, VB and C++ flavors. These projects don't build anything, but it's a convenient way to include some related directories/files.

  • Add a new Shared Project to your solution with the desired directory name.
  • Copy all your secondary files to the new directory.
  • Select "Show All Files" in the Solution Explorer.
  • Select the files, then right-click and select "Include in Project".
  • You can now view the file structure and open the files as part of your VS solution but VS will not try to build anything for that Shared Project.
  • If you have Source Control enabled, VS will also check-in those files (unless you mark them as excluded).
Dean Wiles
  • 41
  • 1
1

One option is to add an extension: "Add Folder as Solution Folder"

With this extension you can do this:

right click the solution > Add > Add Folder as Solution Folder

Andrew
  • 18,680
  • 13
  • 103
  • 118
  • This is what I just did for VS2015 - https://marketplace.visualstudio.com/items?itemName=CeciliaWiren-CeciliaSHARP.FolderToSolutionFolder – CT14.IT Sep 08 '21 at 09:28
0

If I get you right, you'd like to have the projects organized in your solution. Not sure if this fit your scenario, but if you choose a ".sln" (switch file-extension in the filebrowser-Dialog) when adding existing projects to your actual solution it will add all the project organized as they are saved in the sln to add. (VS2017)

PS: Yes, I see this is a 7 Years old post :)

dba
  • 1,159
  • 1
  • 14
  • 22
  • nope, it wasn't about organising projects - it was about solution level files outside of projects. – Shevek May 29 '18 at 15:34
  • what i described is on solution level :) if you have e.g. a libs.sln (having the libs loaded - and "organized" - meaning of displayed in a project-folder stucture) then on adding libs.sln to your main.sln imports it by maintaining the project-folder structure of the libs.sln - okay, maybe i'm still not on the right track :) - sure, you need to add those folders once... but can reuse them again and again – dba May 29 '18 at 15:39
  • Ah, I misread your answer, yes, I can see what you are saying now. I wasn't aware that you could add a .sln as a child of a .sln - interesting! – Shevek May 29 '18 at 20:16
  • actually this wont add the sln as child, but includes the structure of it, meaning if you change the structure in the lib.sln, it won't be reflected in the main.sln (AFAIK), this is one-time import :) – dba May 30 '18 at 08:52
0

One Option would be to write a little exe and add this as external Tool to VS. Basically you would need to edit the sln file (plain text) by adding the folders as "Projects"

...
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mycsproj", " 
[somerelativepath]\mycsproj.csproj", "{projGUID}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FolderName", 
"FolderName", "{FolderGUID}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SubFolderName", 
"SubFolderName", "{SubFolderGUID}"
EndProject
...

{FAE04..} shall be the Project Type GUID for CSproject
{2150...} would be the Project Type GUID for Project Folder

And define the hierarchy in the section

...
GlobalSection(NestedProjects) = preSolution
{projGUID} = {SubFolderGUID}
{SubFolderGUID} = {FolderGUID}
EndGlobalSection
...

Now it's up to you to write some exe, reading the folder info of the libs from the disk and write according Project-Folder Infos in the sln. This should not be a huge effort :)

So whenever you collect multiple projects to your solution, you hit your ext tool and have the connected projects structured fine.

And still I might be on a false track understanding your issue:)

dba
  • 1,159
  • 1
  • 14
  • 22