Add a folder structure to a Visual Studio Solution
Asked Answered
G

6

17

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.)

Genna answered 10/5, 2011 at 14:22 Comment(11)
Solution folders do not map to actual folders in the file system. You need to use project-level folders, instead.Capitulate
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 DLLsSauerkraut
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.Sauerkraut
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.Genna
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.Sauerkraut
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.Dysphoria
No it is not possibleSauerkraut
Unusual that a non-answer is selected as the correct answer.Annatto
@Annatto erm, there isn't a selected answer??Genna
@Genna A mod just deleted the selected answer I guess.Annatto
see #267700Sigma
K
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.

Kovrov answered 10/5, 2011 at 14:33 Comment(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.Kovrov
T
5

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.

Theisen answered 28/5, 2021 at 12:36 Comment(0)
K
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).
Knock answered 16/11, 2021 at 15:58 Comment(0)
A
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

Annatto answered 26/1, 2020 at 22:19 Comment(1)
This is what I just did for VS2015 - marketplace.visualstudio.com/…Truckle
B
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 :)

Biogen answered 29/5, 2018 at 11:54 Comment(4)
nope, it wasn't about organising projects - it was about solution level files outside of projects.Genna
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 againBiogen
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!Genna
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 :)Biogen
B
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:)

Biogen answered 29/5, 2018 at 16:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.