Search code examples
c#visual-studiodirectoryorganization

What is the use of folders inside a Solution or Project (in Visual Studio)


I've been messing around with some public and work Git repos (all Github), as I grow my burgeoning C# expertise...

Especially for tutorial and course repos, they use a lot of folders. I also noticed you can add a "Solution Folder". However, I've also noticed Visual Studio has this love-hate relationship with folders, and sometimes they map to the physical folder, and sometimes they... just don't.

So - what can I use them for? Is there a good use case beyond just logically grouping files in a project to organize things a bit?


Oh! And one time I opened a folder from my drive directly in Visual Studio, and it showed up just like a solution - but it was just an open folder... it was kinda weird. What's up with that?


Links to Info

This Q&A (Actual folders in Visual Solution Explorer?) explains some more about how to keep folders in a solution mapped to the physical folders, which VS is very picky about and doesn't even try to keep in sync...


Solution

  • If I'm understanding your question correctly, there is essentially two most common uses for folders within your solution/project.

    First and probably most obvious, folders are used to organize and group together relevant files. While this is more of a personal preference thing - I often use folders to organize my code similar to that of MVC (Model View Controller).

    Second and usually less common but still something to be familiar with are folders that get copied into the output directory. These folders get created when you have a file with its advanced property Copy to Output Directory set to Copy always or Copy if newer. These files then become a part of the Build Action - upon building your solution, these files get copied to the output directory. This is used when there is a need for certain files within your solution such as a data file or external resource needed to interact with.

    Example: I recently worked on a project that required my solution to interact with PhantomJs, which is an external standalone executable. I needed my code to make calls and pass data to this application - thus making it a vital part of my solution. PhantomJs was placed in a folder and set to Copy if newer which ensured my copy of the executable was an available resource during runtime.