10

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

Community
  • 1
  • 1
kmiklas
  • 13,085
  • 22
  • 67
  • 103
  • You can make folders in Solution Explorer. That is what I do in my projects. With that said I am using `CMake` to generate my projects. I have `CMake` add solution folders to most folders in my source code however it does not exactly match the directory structure. – drescherjm Mar 23 '17 at 20:00
  • Can a large project that already has files arranged in a directory structure be imported, and appropriate folders created automatically in VS? – kmiklas Mar 23 '17 at 20:02
  • I don't know of a non `CMake` way. – drescherjm Mar 23 '17 at 20:03
  • Possible duplicate of [Visual Studio as Code Browser : How to preserve the directory structure?](http://stackoverflow.com/questions/2251201/visual-studio-as-code-browser-how-to-preserve-the-directory-structure) – 463035818_is_not_an_ai Mar 23 '17 at 20:03

1 Answers1

7

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.

Community
  • 1
  • 1
kmiklas
  • 13,085
  • 22
  • 67
  • 103
  • I find learning Visual C++ to be stunningly complicated. No wonder Java took off. I'm now trying to figure out what `#include "ABC/ABC_Client.h"` means. Are folders back on the agenda? I thought the prefix was the workaround. – Peter L May 22 '19 at 23:11
  • A ``#include`` statement will do just that: include a file into another. Think of it as a big ole' copy n' paste. In this case, you're including the file ABC_Client.h into your file, which resides in directory ABC. Note that quotes (") means local include, whereas greater-than less-than braces like ``#include `` means include from the system path, typically something like ``/usr/local`` on Linux. – kmiklas May 23 '19 at 20:14
  • 1
    To your meta point, yes, C++ can be complicated, but the upside is that it is fast, powerful, and pays well. Don't hate me for this, but, believe it or not, after a while, it starts to look beautiful. There is a method to the madness--stick with it; you can get it :D – kmiklas May 23 '19 at 20:17
  • Thanks @kmiklas. That's encouraging. Also, I learned about the Macros and file paths, and that VS is traversing the path looking the ABC folder with ABC_Client.h inside. It was a minor victory. – Peter L May 23 '19 at 20:55
  • 1
    Good work, Peter. My advice for you now is to do all the C++ exercises on Hackerrank. Then move on to the Algorithm section, and write them in C++. Not only are they great problems: structured in order of difficulty that touch upon many key points, but also, for most companies nowadays, the first gate in the interview process is a Hackerrank problem. :^) https://www.hackerrank.com/ – kmiklas May 24 '19 at 15:44