开发者

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开发者_如何学JAVA 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?


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.


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.


VS 2012 has a feature that I just found, and it solved this problem for me. It may not be new to VS.

Create a folder under the project with a leading "_" (to get it sorted first).

On the folder's properties set "Namespace Provider" to false.

VS (or ReSharper?) code analysis then does not complain that "the namespace does not match file location", which was the source of irritation for me that would otherwise have kept me from going this route.


Although there is no easy way to add Custom Folder, there is an easy way to "steal" Properties custom folder.

  1. Add a regular folder to the project. For example MyCustomerFolder.

  2. Open proj file xml. Find line

     <AppDesignerFolder>Properties</AppDesignerFolder>
    

    replace with

     <AppDesignerFolder>MyCustomFolder</AppDesignerFolder>
    
  3. Reload the project.

  4. Now you've got a custom folder, that will always stick to the top.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜