locked
How to import folder hierarchy in visual studio

    Question

  • Hi,

    I'd like to know how to import a whole folder hierarchy into a project in visual studio.  It's fairly easy to add an existing file or add new folders.  However, I can't seem to find how to add multiple existing files while keeping their folder hierarchy.  The only way I've seen was to recreate all the folders through visual studio, then move the files into them, then add them to visual studio.  Is there any way to just select a folder and add all the files in it, keeping the folder hierarchy?
    Wednesday, August 26, 2009 1:15 PM

All replies

  • This has always bugged me too, I dont think it can be done!
    Friday, February 12, 2010 11:25 PM
  •  

    maybe late answer...

    simply, drag from windows explorer and drop in the solution explorer of VS!

    Tuesday, May 31, 2011 9:44 AM
  •  

    maybe late answer...

    simply, drag from windows explorer and drop in the solution explorer of VS!


    That won't work because it doesn't preserve the folder hierarchy.
    Saturday, June 11, 2011 1:29 AM
  •  

    maybe late answer...

    simply, drag from windows explorer and drop in the solution explorer of VS!


    That won't work because it doesn't preserve the folder hierarchy.


    I tested it and maybe there is some missunderstanding:

    - You can easily add stuff to projects that way. The folder structure is kept and it works quite nice.

    - You cannot add items to the solution. (You can add items diretly to the solution!). And drag&drop of a folder wasn't even possible to the solution. And keeping a folder structure does not make sense. There is no folder structure as it is on projects! There are solution folders but these have no reference to existing folders. From my understanding the concept is different to the folder concept of projects (where a project has a location on disk and folders are really folders!).

    So yes: This is bugging my too. We store documentation and dependencies in solutions folders which have a coresponding folder in the file system and adding files to such a folder could be easier.

    Regarding the requirement to add multiple files to a projects: Projects also provide a "show all files" functionality and using this, it is really easy to add a folder or missing files from a folder to a project.

    That is, what I saw with Visual Studio 2010. The thread itself is from 2009 and there was no VS 2010 at that time, but we revived this old thread now and today VS 2010 is the latest version.

    With kind regards,

    Konrad

     

    Saturday, June 11, 2011 5:55 AM
    Moderator
  • There are two different types of folders in Visual Studio: Solution Folders and Project Folders. Solution folders appear in the solution explorer like folders with fuzzy edges (that's my best description). Project folders are the typical folder icon that we've all grown to love. The suggestion that one drag and drop a folder structure onto a project results in project folders. That's okay if that's what you want to do. If, on the other hand, one wants to create a hierarchy of solution folders, one (having already performed an exhausting and useless Google search) uses a macro that already ships with VS 2010.

    Here are the steps:
    1. Create your folder hierarchy in Explorer (which I do using a simple spreadsheet to generate a bunch of "mkdir" commands, copy, paste into notepad, and save as CreateMyHierarchy.bat).
    2. In Visual Studio, hit "Alt+F8" to get to the Macro Explorer (or using menus: Tools | Macros | Macros IDE...)
    3. Traverse to Samples | AddDirAsSlnFolder | GenerateSlnFolderOnDirStructure. Double click.
    4. Enter the windows path to the structure created in step 1.
    5. Notice that the solution folder hierarchy has been created.

    I hope you find this as useful.

    James

    Saturday, June 25, 2011 12:03 AM