Project Directory Structure Lost in Visual Studio?

2019-06-19 17:31发布

I'm learning Visual Studio 2015 Community. I'm a seasoned programmer, but new to VS, and the file representation is confusing me. I've created a solution, and added an existing project. VS is showing me all project files (In my case a C++ project, so .c, .cpp, and .h files) on one tree level in Solution Explorer.

In contrast, if I open said project in something like Sublime Text, VS Code, notepad++, or the like, I see the proper directory structure as it sits on the disk drive; as one would see it in File Explorer/Finder or ls/dir in a terminal.

I have done my homework before I posted, and in the following thread, @Andrey states:

I am afraid there is no such concept in MSVS like "directory structure". Moreover, MSVS doesn't really need it because it uses flat projects and hierarchies are based on project level, not on the file/directory level.

As there is no such thing - you can't have it neither automatically nor manually. MSVS has solution folders which is quite different thing and there isn't much sense in expressing real folders as solution folders.

Visual Studio as Code Browser : How to preserve the directory structure?

Is this true? There is much meaning in the arrangement of files, and the flat representation in VS makes a project harder to understand; file location in the directory structure are important. Is there a way to view the proper directory structure in VS?

In my situation, I'm working with Quickfix, which supports multiple versions (4.0, 4.1, 4.2, etc.). Each of these have different classes and files with the same name.

As you can see from the screen shots below, they are all neatly arranged in different folders on disk, but VS's representation of these files is immensely confusing:

enter image description here

enter image description here

1条回答
孤傲高冷的网名
2楼-- · 2019-06-19 17:33

I found the answer given by @Paul Easter in the thread below to very helpful in understanding this "quirk," which is really a "feature." A different concept of project structure is at work:

But as for the reason you do not want solution folders to behave like "physical" folders is because your solution layout may not necessarily use the same convention as your source control layout. Solution folders allow you to customize the hierarchy of your projects so that you can group projects and items together any way you like, and then decide you don't like it and change it again without having to go through the nightmare of moving source control items around and irritating the rest of your team.

Visual Studio Solutions Folder as real Folders

Is this a good idea? I can see where some people would like it, as it allows them to arrange project files as they wish. At this point, I dislike it; I'm sure in part because it is new to me, but also for these two reasons:
1. In an organized project, the directory hierarchy is not arbitrary; the Principal Engineer arranges files in a certain way for good reasons.
2. It adds a layer of abstraction between the VS file representation and the operating system structure. I like direct access to the files that I'm working on; with the VS system, I feel oddly and eerily disconnected from the underlying files in VS. I must admit a fear that this layer has its anomalies, and will cause problems for me.

查看更多
登录 后发表回答