开发者

Create file/folder structure in VS 2010

I am somewhat of a novice and am seeking some help.

I am working in Visual Studios 2010 and have my solution that has my project that I am currently working on. Specifically I am working on a Win32 Project. I don't know if that is important to know or not.

I have made a file/folder structure in the directory I am working on to help organize my sources. I would like to mimic that in the project but can't. After organizing my sources it says that some can't be found when I compile. I have alleviated some of the problem by editing some of the #in开发者_如何学JAVAclude statements but there are still some I can't fix as they need to include a file from one folder higher (I guess the parent folder?) and I don't know how to do that in an include statement.

Is there anyway I can have actual physical folders in my project that mimic my structure? If so will it handle the #includes fine? (IE if I say #include "BaseClass.h" and its in the folder one higher (again I guess parent folder?) will it find it?).

I've tried dragging my files/folders over from the solution explorer but it just adds them. I have also tried to use the Add New Filter (it has a folder icon) and it does indeed create a "folder" in the project but they aren't physical folders. They are just there to help organize the files in the Solution Explorer for the project.

I've tried Google searching:

create folder visual studio 2010 project add folder visual studio 2010 project create file structure visual studio 2010 project

And they just direct me to drag over the folders from my Solution Explorer and again they don't actually add the folders. They do speak of a template but I don't know if thats what I need to do. I am not technically skilled enough yet to understand it all so would need to do more research. Any pointers/help would be much appreciated.


The way to add physical folders to a project is this:
Create the physical folder in Windows Explorer.
Select the project in Solution Explorer and click Show All Files.
Right click the folder and select Include in Project.
Now you have the folder defined in the project and you can right-click on it and do Add New Item and the new item will get created in the physical folder.

Caution - if you create a Class, the namespace will include the folder name.

It's a little different at the solution level since Show All Files doesn't work and there is no Include in Solution.

What I've done is create the physical folder, then do Add New Solution Folder and give it the same name. Seems to work.


You can fix failure to include by appending ";.." (this means "one level up from here") to the list of include paths to check. Right click 'Project', select 'Properties', locate 'C/C++', 'General', 'Additional Include Directories'. Make sure you do this for both Debug and Release configurations.

I've always found relating Visual Studio folder structure in Solution Explorer to the physical files painful, so I generally avoid this.


So you have some structure on the file system

A
 A.sln
 A.prj
 A.h
 Base
  B.cpp
  B.h
  Derived
   C.cpp
   C.h
   D.cpp
   D.h
 SomeOther
  E.h

C and D can refer to B in various ways
#include "../B.h"
or
changing the project settings to add to the include folder list "Base" then
#include "B.h"

C and D could also refer to A #include "../../A.h"
or SomeOther #include "../../SomeOther/E.h"

'..' in a path indicates to go up one parent
prefer unix style '/' to windows style '\' for portability, but either will work.

Be cautious with structure, MSVC doesn't help you manage it like eclipse helps manage packages in Java, it can become more of a hassle than a help if you make too many small folders.


In the solution explorer, right click and choose Add Project Folder (or something similar, I don't have VS available to view right now). You shouldn't move the files in Explorer after they have been created in VS, as it will affect all the references.

Whenever possible, perform all file moves/renames/changes within the VS IDE.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜