DEV Community

Cover image for Visual Studio, Why Can't You Just Let Me Have This One (Solution Folder)?
Rion Williams
Rion Williams

Posted on

Visual Studio, Why Can't You Just Let Me Have This One (Solution Folder)?

This was originally posted on my blog.

If you've ever worked in a large code-base of around a hundred or so projects, then you know that organizing your code can almost be as important as writing the code itself. Organization is always subjective, sometimes multiple projects are enough, sometimes it can help to organize code into things like Solution Folders, which you'd imagine would be pretty simple - but that's not always the case as you'll soon see...

Naming is hard; Naming Solution Folders is impossible.

While it's well documented that naming things in software is challenging, you can generally come to a consensus amongst your team on what to name something. Apparently, solution folders in Visual Studio are completely different animals and the flagship IDE simply won't let you name a solution folder the same as an entity that exists within your project already:

So after a bit of searching around - I wasn't really able to come across a clear cut solution or workaround, so I decided to write up a short post on one that I came across. Basically, Visual Studio has a bit of trouble attempting to create a logical folder of a given name when a physical folder (or some other entity like a project file) shares that same name. The trick here is to simply create a new Solution Folder with a throwaway name:

Then move the contents into the folder that you'd like (at least the entity with the conflicting name):

Finally, safely rename the folder to the name of your choosing:

the world is right

And that's it! Now you can easily organize your larger projects and solutions, regardless of the name that you intend to you and if it conflicts with other entities in your project.

Latest comments (6)

Collapse
 
leximize profile image
Leximize • Edited

Actually, from what I can see in VS2017 solution files, a Solution Folder is now created IN the .sln file. So, if you add a project of name "TestFolder" - you'll have a project in the .sln of that name. Trying to add in a Solution Folder (which is only a virtual folder in the file system) VS won't let you add a same named project.

This is the SLN contents of a solution with ONLY a Solution Folder in it.

Microsoft Visual Studio Solution File, Format Version 12.00

Visual Studio 15

VisualStudioVersion = 15.0.28307.645
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestFolder", "TestFolder", "{01F7F854-0EC2-47D2-AF62-97CAC80C3294}"
EndProject
Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5E6FC95B-7995-413A-A37A-102F5797AEF0}
EndGlobalSection
EndGlobal

Collapse
 
thejoezack profile image
Joe Zack

Great find! I had just assumed it was illegal.

Collapse
 
cookrdan profile image
Dan

I suspect this isn’t actually VSCode’s fault. If I remember correctly a folder is basically a file just a certain type. You can try in terminal and you still have the same problem:

# make a file:
touch some_name

# make a folder with same name:
mkdir some_name

# error:
mkdir: can't create directory 'some_name': File exists  
Collapse
 
cookrdan profile image
Dan • Edited

More on the above and maybe a little solution (in bash):

# make a file
[~]$  touch some_folder                                    

# make a folder with the same name (won't work)                                           
[~]$  mkdir some_folder                                    
mkdir: can't create directory 'some_folder': File exists   

# okay so instead make a _tmp folder, move the file(s) in there, then rename the _tmp folder to intended name                                                          
[~]$  mkdir _tmp; mv some* $_; mv $_ some_folder           

# here's the folder                                                           
[~]$  ls                                                   
some_folder                                                

# here's the contents of it                                                           
[~]$  ls some_folder/                                      
some_folder

$_ in bash is the last parameter given to the previous command.

Collapse
 
rionmonster profile image
Rion Williams

Hi Dan,

Thanks for the reply, I’m sure the mkdir tip will be helpful to someone that hasn’t encountered it before.

It’s worth noting that this is regarding Visual Studio proper as opposed to Visual Studio Code, which in this scenario will make a bit of a difference. Visual Studio has a concept of Solution folders, which are logical and this don’t necessarily map to physical ones on disk.

The issue here was that I already had a project (and project folder) of a specific name, Foo.Logging. As time passed a few other logging specific implementations such as Foo.Logging.Serilog, Foo.Logging.log4net, etc. came along, which for organization purposes I wanted to house in a single, logical solution folder called “Foo.Logging”, and thus the issue arose can which is almost assuredly a Visual Studio tooling issue as opposed one a simple naming conflict.

I hope that makes sense - and thanks again for the read/reply.

Collapse
 
cookrdan profile image
Dan

AH! I misunderstood that it wasn’t vscode. Haha!
I was curious about your screenshot - so similar but a little different.
Yeah I agree it looks like an issue with the tool then. Is there some place to report it/request a fix? I’ve never used Visual studio