Tip: Visual Studio Custom File Nesting

Posted by

One of the niceties of Visual Studio is the ability to nest files under similarly named files. If I have appsettings.prod.json and appsettings.qa.json in the same folder as the appsettings.json, they will nest under appsettings.json. While it doesn’t recognize every file extension, you can create a custom file nesting json configuration, which is good because I have multiple .yml files that follow that same pattern.

If you look closely at the options in the solution explorer, there’s a diagonal line that is really an icon of nested boxes. After clicking this button’s dropdown menu, you can choose to “Add Custom Settings”.

After clicking this, you get an option to create a custom settings file that you can base off of the Web nesting settings. Within the dependentFIleProviders pathSegment, you can add a custom file extension, such as “.yml”.

Saving it and changing the current settings to the newly created custom settings applies almost immediately, and my .yml files are now nested.

This settings file is stored in the %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\NestingProfiles folder, so it won’t be added into the direct source code. That is to say, this settings file is a Visual Studio configuration file, not a part of the code project. This is unfortunate because that settings can’t be easily shared via the source code, but is also very nice because those same nesting settings can be leveraged regardless of what project you have open.

I will admit this isn’t much of a seriously beneficial feature of Visual Studio, but it’s a pretty nice one for keeping your solution explorer easier to navigate.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.