Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Solution -- Any way to create a "special" folder?

Basically, I want one of my folders to appear above the other folders as a type of "special folder", similar to how Properties has it's own special place even though it's a folder, same with App_Data, etc.

Is this possible?

like image 213
michael Avatar asked Jun 01 '11 14:06

michael


People also ask

How do I create a special folder?

To create a folder, right-click, then select New>Folder. Right-click in File Explorer, then select New>Folder. In Windows 7, there is a New folder button near the top of the window. In Windows 10, you can also click the Home tab, then the New Folder button.

How do I add a folder to Visual Studio solution?

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.

How do I create a folder and code in Visual Studio?

The File > Add Folder to Workspace command brings up an Open Folder dialog to select the new folder. Once a root folder is added, the Explorer will show the new folder as a root in the File Explorer. You can right-click on any of the root folders and use the context menu to add or remove folders.

How do I create a subfolder in Visual Studio?

To create a subfolder, start by right-clicking an existing solution folder and then choose the same menu options. When the folder appears, type in a new name. You can also create solution folders using options from the Project menu.


2 Answers

By default, Visual Studio doesn't support adding special project folders. The Properties folder is hard-coded to behave the way that it does.

However, anything is possible with code. You could build an extension to do this, but it wouldn't be simple. You'd probably need to mess around with the IVsHierarchy or even implement a project subtype.

like image 72
Matt Avatar answered Sep 22 '22 20:09

Matt


Basically, I want one of my folders to appear above the other folders as a type of "special folder", similar to how Properties has it's own special place even though it's a folder, same with App_Data, etc.

Is this possible?

Yes:

  1. Do it manually through the IDE
  2. Write your own script to generate/modify your *.sln/*.vcproj

For (1) "manual" on solutions in the IDE: Solution Explorer, right-click on Solution node==>Add==>New Solution Folder.

While typically the folders are sorted alphabetically (I'd insert a leading underscore to force your special folder to the top), solution folders inserted manually on my MSVS2008 leave the new folder "at the top", even though it should have bumped down when alphabetically sorted. However, folders under a Project (which are called "Filters") are always sorted alphabetically, and added similarly from the right-click, and then you can modify their "filter properties" with file name globs for what you want in there (e.g., add a filter glob for "*.MY_EXTENSION1;*.MY_EXTENSION2").

We chose (2), and we generate our own *.sln and *.vcproj, adding our own folders/filters. I've not seen any utilities on the web to help with that (so we had to write our own). The formats are not too hard to reverse engineer, but it's largely undocumented XML, so you have to experiment. There are only a couple good web articles explaining what's in the file, like this one:

http://tim.oreilly.com/pub/a/dotnet/excerpt/vshacks_chap1/index.html?page=4

On the "bright side", the files are only XML, so in developing our scripts we merely made changes through the IDE, saved, and compared the "diffs" for what change we want. Those changes are what our scripts insert when we modify our files. So, if you modify the file manually, you can similarly just "diff" the file to see what changed, and make your own script. (IMHO, this is the fastest and easiest route, since tools generally do not exist to manipulate these files.)

Tools like CMake and QMake generate *.vcproj/*.sln, but don't really do the folder customization thing like you're talking. However, we look at their output too, because, "there's more than one way to do things" in these files, and the files seem to have many undocumented features for doing different clever things that somehow these tools have "discovered" (so you can try to copy their generated output).

We found the .NET APIs to work with these files as too much work, and not really designed for that type of manipulation, but YMMV.

like image 41
charley Avatar answered Sep 23 '22 20:09

charley