简体   繁体   中英

Actual folders in Visual Solution Explorer?

MS Visual Studio has Solution Explorer where I can see all project files, I can also create filters which are like folders for files to keep them in groups. The problem is - I want my files divided in groups both in Visual and physically on my disk. But I don't want to have to apply each change twice both in Visual and on my disk. Is there any way to show actual folders, in which I keep my files on disk, in Visual Solution Explorer (and no - "Show all files" doesn't do that, I've just checked)?

No - SE and the Filing System hold independent copies of the structure/hierachy information.

I usually disable the filters and put files where I want them, so that the two structures remain in sync by default (indeed, any other way seems like madness if you want to have any kind of organisation of source code - I always group files for components inot separate folders).

Then (with filters disabled)...

If you create the folders in Solution Explorer, and use the context menu from that folder to "Add new item..." or "Add existing item" then the disk structure will reflect the solution explorer (existing items are copied rather than referenced from where they currently reside to ensure this, which can result in old copies of files being left around your project if you add to the wrong SE folder). Otherwise it is usually only if you "add as link" that VS will put an item in a different folder in the SE than it appears on disk.

To tidy things up, the easiest approaches are (after making a backup copy just in case):

  • Open the solution and file explorers and manually "diff" them. Any files that are "wrong" should be removed from SE, moved to the correct disk location, and then added to SE by using the context menu for the correct SE folder .
  • If there aren't too many folders, a simpler approach is to just remove all files from solution explorer and then add them (one folder at a time) back into the project, ensuring that you create the correct folder names as you go, and add from each folder's context menu. By rebuilding the SE from scratch you can fairly quickly sync the two layouts, and this can often be easier than trying to work out where the differences lie.

Once they're in sync, only use the SE to manage the files, and be careful to add items using the context menu from the correct folder. If you move things about on disk, you'll break the links.

如果单击“显示所有文件”,则会将解决方案资源管理器从显示文件的虚拟过滤器切换到文件的物理过滤器。

By filters I think you are referring to Solution Folders. Those are virtual folders that have no bearing on the file system. A trick I did is make a throw away project. Items added to project folders maintain their relationships. It is a hack, but it works. If someone knows a less hacky way to do it, I'd love to know, too.

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