How to import files with directory structure in visual studio 2013

I have source code for a C ++ library (its Box2D version)
I would like to add parts of it to a new project and build it into a .dll

However, when I add a directory of files that I want to a new project, it adds them all to the root of the project, and as a result, most if the assertions included are wrong. eg...

#include <Box2D/Dynamics/b2Body.h>
#include <Box2D/Dynamics/b2Fixture.h>
#include <Box2D/Dynamics/b2World.h>

      

The "Box2D / Dynamics /" part is now incorrect.
I add new files by placing the directory containing the files I want in the new project directory, then click the show all files button, then click on the folder and say include in project

This is what the original project looks like (from which I copy the file directories).
enter image description here

and it looks like what my new project looks like. As you can see the whole project is "flat", all files are in the root of the project (although in the actual directory of the project the subdirectory structure is still present)
enter image description here

tbh I've always found this aspect of visual studio file management odd and confusing

+3


source to share


3 answers


The reason you don't see folders when importing files is because there is no folder to talk about. Since you can see the filter overlay on the folder icons, there are only filters. You can also view the properties of these folders to see what files are listed in that folder.



VS2013 uses projectFile.vcxproj.filters to manage filters. You can try copying this file (or manually creating it) to a new directory and then importing the code / header / other files. AFAIK, VS has to select the correct folder for the file by looking at the file extension.

+1


source


I am using VS2013. It looks like the New Project from Existing Code wizard will preserve the existing directory structure of the source tree if you create a project in a custom location; that is, somewhere other than:

C:\Users\*yourUserName*\Documents\Visual Studio 2013\Projects

      

Here's how I imported the existing C ++ source tree into VS2013:



  • File> New> Project from Existing Code ...
  • Select Visual C ++ and click Next
  • Set project file location to something other than C: \ Users * yourUserName * \ Documents \ Visual Studio 2013 \ Projects
  • Use the Add button to add a source tree. You can just add the root of the source tree and all your subdirectories will be preserved.
  • Fill in the rest of the wizard as you see fit and click Finish.

As others have noted, the Show All Files button (or Project> Show All Files) toggles between the tree view and the β€œother” view of sources in Solution Explorer.

0


source


I made an extension for this purpose: https://visualstudiogallery.msdn.microsoft.com/5a3251d7-3228-4813-a67e-6b9cc83d0507

The sources are here: https://github.com/Dllieu/VisualStudioCppExtensions

Once you import all your files (like the same as the second screenshot), you just need to right click on the C ++ project and click Generate C ++ Project Filters, it will create the whole filter to replicate the folder hierarchy your files

0


source







All Articles