Visual Studio Tip - Solutions and Folders

  • By Ivan Gavryliuk
  • In Visual Studio
  • Posted Thursday, January 31, 2019

Did you know that by default Visual Studio displays solutions in something called a "solution explorer view"? For instance, I have a solution (an example from Storage.Net) that is organised into solution folders, the default. On the file system it's organised to the best effort. Of course I have, or was trying to have, a well organised folder structure on disk, such as:

  • src for source code
  • **doc **for any documentation
  • test for any test projects

And so on. To start with, it was OK. I was putting the appropriate project into an appropriate folder when creating new projects in the solution. Then number of projects started to grow and some of them need to be organised into categories like Azure or **AWS. **And in order to do that, I was creating a new solution folder in VS and dragging a project into it. It's actually a neat feature, which allows you to visually organise projects into appropriate categories, however it's completely out of sync with folder structure on disk, as you can see below - Azure projects are in the same disk folder as the rest of them.

To solve this problem, you need to manually synchronise solution folders with disk folders, i.e. create solution folder first, then create a folder on disk, and make sure you put the project into appropriate folder on disk when you're adding it when right-clicking on a solution folder. And it's just too much work, so the structure goes out of sync very quickly.

In addition to that, I like to store my markdown documentation in the same git repository under the doc subfolder. This allows me to make changes to the documentation when I write code, directly in Visual Studio, thanks to Mads Kristensen's awesome MarkdownEditor extension.

In order to keep my markdown files handly, I would normally create a new solution folder called "doc" and just manually add existing files from disk, so I could see them in Solution Explorer:

It's sort of OK if you have one or two markdown files, however when the number grows, or worse, you start having subfolders in documentation, synchronising those folders becomes a huge pain and I'd just end up opening doc folder in VS Code as a folder to edit it effectively:

It's sort of a shame, because VS markdown editor is far more superior, it supports pasting pictures, TOC, link validation and much more.

This actually bugged me for a very long time, until I've discovered this awesome one-click fix - **FOLDER VIEW. **All you have to do is click that yellow button on top in solution explorer and it switches to the view synchronised with the disk folder structure:

Once done, the solution explorer view is synchronised, and I can immediately see:

  • Where I messed up in disk folder structure, and how I can organise it better.
  • All of the subfolders on disk, including documentation.
  • Any "rubbish" that is on disk but not supposed to be there.

Unfortunately, in this view you cannot do particular features on projects, for instance you can't see the list of assembly references or nuget packages, so you have to switch back to solution view anyway. However, if you prefer to edit your .csproj files manually, this is even better, as you can see .csproj file in the folder view and can just click on it to open for edit (new .net project format only, not true for old style net framework projects).

You will also be closer to the view you can see in other IDEs like VS Code or IntelliJ ones (IDEA, Rider etc.) so it's actually a good thing - get used to it.

I still can't believe I've missed this feature, and that I'm writing a blog post about it. I guess this is just excitement.

Thanks for reading. If you would like to follow up with future posts please subscribe to our rss feed.