How to add a directory structure to a project ?

I have some code that I need to include in my project. The code is organized in a directory structure, such as:

Directory1 - Directory2 - Directory3 - Lots of C# files.

- Directory4 - Lots of other C# files

I right click on the project, and select Add Existing Items, but it would not retain the directory structure, all files are added to the project directory.

If I want to retain the directory structure, the only thing I can do is to manually create a directory structure as the structure of the external code. Go to each directory and import the files in the corresponding directory of the external code.

Its the same for both Visual Studio 2003 and 2005.

Is there a better way to do it Or let me rephrase my question, what would be the best way to include a whole external directory structure to your project

Thanks for your help.



Answer this question

How to add a directory structure to a project ?

  • JoeL7034

    Hi,

    The directory structure of your project has as root the project folder, if your directory structure is inside of your project what you can do is to enable "View all files" in your solution explorer and all the folders will appear (ghosted those that are not included on the project). What you can do is right click on those folders and set "Add to Project". Then, all those folders will be included as "namespaces".

    Now, if the structure is in another place you will have to manually copied to your project root (as VS needs the files there and that's why when you add a file it just copies the file into your project folder).

    Regards



  • Walter Luszczyk

    I'm not sure if you're already do this, but, you can create folders in your project. Right-click the project in Solution Explorer and choose Add + New Folder. When you want to add a project item, right-click that folder and choose Add + New Item. It will be created in a subdirectory of your project directory.

    With some skillful notepad editing of your project file, you should be able to have the project in Solution Explorer match the directory structure...


  • Radomiak

    Excellent, SalvaPatuel,

    I followed your instructions and it worked perfectly.

    Thanks a lot.


  • How to add a directory structure to a project ?