Reputation: 181044
I have a Visual Studio Solution. Currently, it is an empty solution (=no projects) and I have added a few solution folders.
Solution Folders only seem to be "virtual folders", because they are not really created in the Filesystem and files inside solution folders are just sitting in the same folder as the .sln file.
Is there a setting that i've overlooked that tells Visual Studio to treat Solution Folders as "real" folders, that is to create them in the file system and move files into it when I move them inside the solution into one of those folders?
Edit: Thanks. Going to make a suggestion for VS2010 then :)
Upvotes: 183
Views: 97443
Reputation: 17
Upvotes: -1
Reputation: 738
This is actually very easy to do:
Upvotes: 1
Reputation: 11901
Install and run the open-source sln-items-sync dotnet tool as follows:
dotnet tool install --global sln-items-sync
sln-items-sync --solution some-solution.sln [files and folders to add ...]
e.g.
sln-items-sync --solution some-solution.sln .github/ README.md .editorconfig
Tool source/website: https://github.com/timabell/sln-items-sync
I created it as an xmas hols project as my gift to the microsoft devs of the world because I also got fed up after 15+ years of manually syncing the folders.
Upvotes: 0
Reputation: 869
This is now supported in Visual Studio 2022. It is now a hybrid folder.
Upvotes: -1
Reputation: 713
You can just sync your new solution folder nesting level and also name with the actual filesystem folder and it works like a charm!
Upvotes: 11
Reputation: 2803
For C# in Visual Studio 2019 I used this way (Seems to be similar to this answer, but that didn't work at least in C# solutions)
switch views
folder view
switch views
again and choose the solution.... just open a solution with multiple projects and try to move the projects to some other real folders through the folder view. The issue is VS doesn't update paths to projects in a solution file
Upvotes: 6
Reputation: 178
Though this is an old topic, I will add my answer, because I had the same issue and searched for a solution but it seemed that everyone is 100% sure that there is no way to do it. So I started to experiment with VS 2019, tried a lot of settings, and eventually figured the way out.
You only need to click 1 button - Show All Files
, and you will see the physical structure of your Visual Studio Solution:
Right-click on your project → Add
→ New Folder
Note that the option changed from New Filter
to New Folder
Project
include
, src
, data
, libs
, etcCrazyDemo
, not theSolution 'CreazyDemo' (1 of 1 project)
Project
→Properties
Configuration Properties
→VC++ Directories
tabInclude Directories
and set to $(ProjectDir)/Project/include;$(IncludePath)
Library Directories
and set to $(ProjectDir)/Project/libs;$(LibraryPath)
Source Directories
and set to $(ProjectDir)/Project/src;$(SourcePath)
Scope to This
option if you want to focus on 1 project. Just right-click on the Project
folder and press Scope to This
Project Properties
you need to click on any of your project files (like main.cpp
in the example) and then click on the editable client area (like when you want to change the code) and only after that you'll be able to see the Project
→CrazyDemo Properties
option. [Visual Studio is Insane 🤦♂️]
Upvotes: 0
Reputation: 679
Create an empty solution then open .sln file in an editor and put these lines of code after MinimumVisualStudioVersion
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9D8C3BB1-AEDB-4757-8559-995D12A4E6D0}"
open the solution in vs and you should add the same folder to it now you can see the folder and add a project to it you have a real folder in windows and a virtual one in vs
be sure that you created the projects with that path
Upvotes: 4
Reputation: 11972
The chosen answer suggests it would be possible to use actual projects instead of solution folders, but does not really explain how. I guess what I'm describing here is possibly the least awkward way of achieving that... :-P
The problem with regular project files is that they eventually will be compiled by MSBUILD
. And if you want have a project which only contains non-compilable files, that will be an issue.
But some time ago Visual Studio introduced a new project type: Shared Project (.shproj extension). This project type does not get compiled by default, but only when (and only if) it is referenced by another project.
So one part of the trick here is to use shared projects instead of solution folders. It's obviously possible to add a shared project that is never referenced by any other project, meaning we can avoid the issue presented above.
Then, by using <None Include="**/*" />
clause in the .shproj file, we can make it automatically reflect any new files and/or subfolders.
So basically do this:
For instance, in my case, I've created a DockerDev.shproj, so I can group some docker-related scripts that we run only in our development machines:
<?xml version="1.0" encoding="utf-8"?>
<!-- DockerDev/DockerDev.shproj -->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="**/*" />
</ItemGroup>
</Project>
This .shproj file will keep track of any file, in any subfolder of this new DockerDev
folder in my solution.
As far as I could see, this solution works pretty much like what the OP requested: it will work as a non-compilable reference to a folder, and it will automatically reflect any changes made to it.
Upvotes: 15
Reputation: 4986
In Visual Studio 2017, click on the "Solutions and Folders" icon in the Solution Explorer window. This button toggles from the virtual "solution" view into a "source view" that matches the layout of folders and files on the file system. When you add a new folder, the folder is physically created in the expected location.
.
Upvotes: 52
Reputation: 1872
Create "Solution folder". This will create logical folder, but not physical one. Right click to the solution folder and open a new project dialog. But before you click OK, you have to change a project location to your desired physical folder and VS will create it and place the project inside.
Upvotes: 3
Reputation: 4925
Note: Yes this is possible you can create a folder on root but its lil bit tricky....
By giving some extra efforts you can do it How? Lets follow the step--
6.Take the repository on fresh location.
YOU are done...
if still you are not able to see your folder -----
Congrats you are done..
If you face any problem just write me for help..
Upvotes: 1
Reputation: 71
Folder To Solution Folder By Cecilia Wirén - CeciliaSHARP
Remove the hassle of adding several files to solution folder. Just use the context menu for the solution and just below the option of creating a new solution folder you now find 'Add Folder as Solution Folder'. This will create a solution folder with the same name as you selected and add the items inside of that folder to the solution folder. This will not move the files on disk.
Upvotes: 7
Reputation: 684
There is a workaround, that actually behaves as expected.
Done. Now Solution Explorer will reflect any change in the file system and vice versa (including subfolders).
I (miss)use it for specs, docs, PM and some DevOps scripts that are shared within the team. It's easy to choose, what to include in source control or not, and (if set up correctly) it doesn't conflict with build.
I know the feature is not intended for that use case, but except for the maybe misleading "Project" icon I didn't find any shortages to that hack yet. And there still are use cases where the classical (virtual) Solution Folders that VS provides, fit in the picture. What do you think?
Upvotes: 58
Reputation: 1105
Sara Ford contributed a Macro to add do this. In Visual Studio 2010, if you open your Macro Explorer, you will see a macro called "GenerateSlnFolderOnDirStructure." This will automate the creation of the Solution Folders and add the files.
Upvotes: 8
Reputation: 42350
I have a bit of a workaround for this (it's not great, but it works).
It's not great because you will need to manually maintain the file references, but it works for me.
Upvotes: 0
Reputation: 31
Visual studio has no support for this. I made an extension that does something similar for VS2013 though. It maps solution folders to physical folders on your hard drive, though the mapping is one way (from hard drive to solution). That means a solution folder's contents will reflect the hard drive folder's contents, and not the other way.
With that out of the way, the extension may still be useful. It has support for mapping solution folders to physical folders, filtering files and directories based on regex, and remembering mappings in your .sln file. Properties are non-intrusive so developers without the extension can still open the sln and not be affected.
Hosted on visual studio gallery: https://visualstudiogallery.msdn.microsoft.com/69e19ea6-4442-4cb6-b300-044dd21f02bd
Edit: Uploaded to bitbucket. Now open source. MIT license. https://bitbucket.org/LSS_NorthWind/physical-solution-folders
Upvotes: 3
Reputation: 661
I've wanted this feature a few times myself, but at the end of the day, you really do NOT want the ability to do this. Think of your Solution (file) as as the root of a web application and think of Solution folders as Virtual Directories (literally and functionally). The contents of a web virtual directory could be physically on a different server altogether. Where Visual Studio muddled up the solution folders concept is by allowing you to create new files inside the folder. You should always "Add Existing" when adding content. When you add existing, it creates a link to the source location of the file.
But as for the reason you do not want solution folders to behave like "physical" folders is because your solution layout may not necessarily use the same convention as your source control layout. Solution folders allow you to customize the hierarchy of your projects so that you can group projects and items together any way you like, and then decide you don't like it and change it again without having to go through the nightmare of moving source control items around and irritating the rest of your team.
Upvotes: 2
Reputation: 1097
You can add real folders by choosing "Add new filter" for a Visual Studio project file. You can also do "Add new filter" under an existing folder. Once the folder is created, rename it and add source or header file or whichever suits your project. This is one way I know which lets us create real folders through the Visual Studio IDE.
Upvotes: 2
Reputation: 20692
The folder created underneath the solution will be virtual as said. Maybe this might be called a workaround but you can physically create the folder on disk either before or when you add new item/project and Robert should be a sibling of your dad.
ps- on closer look maybe i should explain "bob's your uncle" means your fine/sorted.
Upvotes: 0
Reputation: 6689
No, it's not supported. As you suspected, solution folders are simply virtual subentries in the .sln file, nothing to do with the file system.
Upvotes: 5
Reputation: 702
No special setting. I don't think it's supported.
You can create real folders in a "project" within the solution, but not in the solution itself.
Upvotes: 56