简体   繁体   中英

Microsoft Visual Studio (2008) - Filters in the Solution Explorer

In the Solution Explorer when working with C++ projects there is the standard filters of Header Files, Resource Files, and Source Files. What I'm wanting to accomplish is essentially Filters by folder.


Lets say the structure of the files was like this:

  • ../Folder1/Source1.cpp
  • ../Folder1/Header1.h
  • ../Folder1/Source2.cpp
  • ../Folder1/Header2.h
  • ../AnotherFolder/Source1.cpp
  • ../AnotherFolder/Header1.h
  • ../AnotherFolder/Source2.cpp
  • ../AnotherFolder/Header2.h
  • ../SomeOtherSource.cpp

In the Solution Explorer, it would look like:

  • Header Files/Header1.h
  • Header Files/Header1.h
  • Header Files/Header2.h
  • Header Files/Header2.h
  • Source Files/SomeOtherSource.cpp
  • Source Files/Source1.cpp
  • Source Files/Source1.cpp
  • Source Files/Source2.cpp
  • Source Files/Source2.cpp

And I would like to have it look like this:

  • Header Files/AnotherFolder/Header1.h
  • Header Files/AnotherFolder/Header2.h
  • Header Files/Folder1/Header1.h
  • Header Files/Folder1/Header2.h
  • Source Files/AnotherFolder/Source1.cpp
  • Source Files/AnotherFolder/Source2.cpp
  • Source Files/Folder1/Source1.cpp
  • Source Files/Folder1/Source2.cpp
  • Source Files/SomeOtherSource.cpp

How would this be accomplished?

显示所有文件?

You are free to manually create folders yourself and move the files around. I agree this is a much more convenient way to arrange files but AFAIK there is no way to make VS do this automatically.

You can create the Visual Studio Plugin to do this. I am not sure how you can access "Solution Explorer" programatically.

The only method I have found for doing this is completely manual. I have created a hierarchy of filters to match the folders. Then, I move to the "Show All File" view, and select a single folder. I add all files from that folder that are not in my solution to the solution. Then I leave "Show All Files.

At this point, VS does not seem to properly update my list of files. So I need to "Close Solution" and re-open the solution. At this point, the new files are in the solution, but not in a filter. They are in the top level, at the bottom of the project. At which point I drag them into the correct filter.

This is tedious, error-prone, and a waste of time. But since my project is built using an external make system, it's the only way I can keep the project reasonably up-to-date and still get decent search and browse behavior in Visual Studio. The time cost pays itself back in productivity later, but I still begrudge it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM