简体   繁体   English

项目中的Visual Studio 2017文件夹

[英]Visual Studio 2017 Folders in Project

I am using Visual Studio 2017 to write some stuff in C. When I open a new project, I have some default filters and in "add" option for the project there's only filter and no folder/directory. 我正在使用Visual Studio 2017在C中编写一些内容。当我打开一个新项目时,我有一些默认过滤器,并且该项目的“添加”选项中只有过滤器,没有文件夹/目录。

I want my project to have a folder structure, but can't add folders to the project in Visual Studio. 我希望我的项目具有文件夹结构,但是不能在Visual Studio中将文件夹添加到项目中。 Looking online I can only find solutions for adding an existing folder to a project and not adding a new one. 在网上寻找,我只能找到将现有文件夹添加到项目而不添加新文件夹的解决方案。

How can I add new folders to a Visual Studio C project? 如何将新文件夹添加到Visual Studio C项目?

How can I disable filters? 如何禁用过滤器?

The way that I think of Visual Studio 2017 (earlier versions of the IDE as well) and its presentation of files in File View is as a kind of virtual file organizing system. 我对Visual Studio 2017(以及IDE的早期版本)及其在File View中的文件表示的看法是一种虚拟文件组织系统。 File View allows you to logically organize files, presenting the actual file system in a more helpful manner. File View使您可以逻辑地组织文件,以更有用的方式展示实际的文件系统。

The icons that look like folders in the File View are not really folders but are instead labels, called filters, which allow you to group your files however you like regardless of how they are physically stored in your persistent storage area such as a hard drive. 在“文件视图”中看起来像文件夹的图标并不是真正的文件夹,而是标签,称为过滤器,它使您可以对文件进行分组,而不管它们如何物理存储在永久性存储区(如硬盘驱动器)中。

Filters are more flexible by not corresponding to the physical file folder hierarchy as they allow you to organize files that are all in a single folder into logical groups. 筛选器不对应于物理文件夹的层次结构,因此更加灵活,因为它们使您可以将单个文件夹中的所有文件组织为逻辑组。 Filters allow this to be done at a finer grain than is typically used by grouping files in folders. 与将文件夹中的文件进行分组所使用的过滤器相比,过滤器可以更精细地完成此操作。 Filters also allow you to group files that are in multiple folders together into a single logical folder within File View. 筛选器还允许您将多个文件夹中的文件分组到文件视图中的单个逻辑文件夹中。

However filters can be confusing because most of us are so accustomed to file folder hierarchies that the filter methodology can disconnect the logical file as represented in a Filter from the physical file location located in a folder. 但是,筛选器可能会造成混乱,因为我们大多数人都习惯于文件夹层次结构,以至于筛选器方法可以将筛选器中表示的逻辑文件与文件夹中的物理文件位置断开连接。

My typical methods of adding files 我添加文件的典型方法

Typically what I do is to create the physical folders through Windows or doing a clone of an existing Git or Subversion or VS Team Services source tree. 通常,我要做的是通过Windows创建物理文件夹或克隆现有Git或Subversion或VS Team Services源树。 With something new I may use the New Solution or New Project wizard to create my initial starting point and then organize and add files and folders physically through Windows and then go into the Visual Studio IDE to create the Filters and then Add existing files to the Filters. 对于新内容,我可以使用“新解决方案”或“新项目”向导创建我的初始起点,然后通过Windows物理地组织和添加文件和文件夹,然后进入Visual Studio IDE创建过滤器,然后将现有文件添加到过滤器。 In some cases I will create sub-filters within a Filter in order to better organize the files within a physical Folder. 在某些情况下,我将在过滤器中创建子过滤器,以便更好地组织物理文件夹中的文件。

For new files I will just use the Add New Item menu option to add the item to the proper project. 对于新文件,我将仅使用“ Add New Item菜单选项将该项添加到适当的项目中。 If you right click on a filter name, the new file will automatically be added to the filter. 如果右键单击过滤器名称,则新文件将自动添加到过滤器中。 In some cases when I have added additional filters to the project to organize files, I will drag the newly created item to the proper filter and drop it there. 在某些情况下,当我向项目中添加了其他过滤器以组织文件时,我会将新创建的项目拖到适当的过滤器中并放到那里。

This drag and drop is not changing the physical location of the file but is changing its logical position by moving it from one filter to another. 这种拖放操作不会改变文件的物理位置,而是通过将其从一个过滤器移到另一个过滤器来改变其逻辑位置。 To move the file physically from one folder to another, I will usually do that with Windows. 要将文件从一个文件夹物理移动到另一个文件夹,通常我会使用Windows。 Just remember that if you do physically move a file with Windows you must also modify the file's entry in the Visual Studio 2017 filter to which it has been assigned, I usually do a Remove on the file followed by Add Existing Item and browse to its new location. 请记住,如果您确实使用Windows来移动文件,则还必须在文件已分配给的Visual Studio 2017过滤器中修改文件的条目,我通常会在文件上执行Remove操作,然后Add Existing Item并浏览到新文件地点。

It appears you can not have the same file in multiple filters within the same project. 看来您不能在同一项目的多个过滤器中拥有相同的文件。

In some cases when I Add New item , I will change from the suggested folder displayed in the Add New Item dialog to a different folder using the Browse button. 在某些情况下,当我Add New item ,我将使用“ Browse按钮从“ Add New Item对话框中显示的建议文件夹更改为其他文件夹。 And if I need a different extension to the file then I will make that change as well, a common action when adding a new C source file to a project which requires changing the .cpp extension to .c . 而且,如果我需要对该文件使用不同的扩展名,那么我也将进行此更改,这是在将新的C源文件添加到项目时需要将.cpp扩展名更改为.c的常见操作。

You can also use the Browse button to navigate to a folder where you can then create a new folder if you like using the right click menu that displays when you do a right click in the displayed list of files and folders. 如果您喜欢在显示的文件和文件夹列表中单击鼠标右键时显示​​的右键菜单,还可以使用“ Browse按钮导航到一个文件夹,然后在其中创建一个新文件夹。

Unfortunately, the Add New Item dialog always wants to put a file into the project directory with all the other files. 不幸的是,“ Add New Item对话框始终希望将文件与所有其他文件一起放入项目目录。 The Add Class wizard doesn't give you the opportunity to specify anything other than the default project folder. Add Class向导没有给您机会指定默认项目文件夹以外的任何内容。 I have in some cases created C++ classes using the Visual Studio IDE, removed them from the project, moved the physical files to where I want them to be and then added them back to the project. 在某些情况下,我已经使用Visual Studio IDE创建了C ++类,将它们从项目中删除,将物理文件移动到我想要的位置,然后将它们添加回项目中。

The filter approach seems to work well because the total solution is divided up into multiple projects and each project has its own physical folder. 筛选方法似乎很好用,因为整个解决方案分为多个项目,每个项目都有自己的物理文件夹。 The multiple projects may correspond to particular DLLs or static libraries or other components that are used by the solution. 多个项目可能对应于解决方案使用的特定DLL或静态库或其他组件。

See also Can I configure Visual Studio to use real folders instead of filters in C++ projects? 另请参见我可以将Visual Studio配置为在C ++项目中使用真实文件夹而不是过滤器吗?

Example screenshots of folder and filters 文件夹和过滤器的屏幕截图示例

Here is a Windows folder view of a small project of the resources being used: 这是正在使用的资源的小项目的Windows文件夹视图:

Windows文件夹的屏幕快照,其中显示文件

And this is how I have the filters set up. 这就是我设置过滤器的方式。 Normally the list of resource files can be quite long however I have created two sub-filters to logically separate out bitmap files from icon files though they both share the same physical resource folder. 通常,资源文件的列表可能会很长,但是我创建了两个子过滤器,以从逻辑上将位图文件与图标文件分离开来,尽管它们都共享相同的物理资源文件夹。

Visual Studio 2017的解决方案视图的屏幕快照,显示相同的文件

Also the filter named PepIncludes corresponds with an actual physical folder named the same while the filters named "Header Files" and "Source Files" are groups of files that all reside in the same physical folder which is named the same as the project folder. 同样,名为PepIncludes的过滤器与实际的物理文件夹相对应,而名为“ Header Files”和“ Source Files”的过滤器是文件组,它们都驻留在与项目文件夹相同的相同物理文件夹中。

The following screen shot shows how filters can provide flexibility. 以下屏幕截图显示了过滤器如何提供灵活性。 I have a folder with include files, PepIncludes, and I have the same collection of files in two different projects within this Visual Studio 2017 solution. 我有一个包含包含文件PepIncludes的文件夹,并且在此Visual Studio 2017解决方案中的两个不同项目中有相同的文件集合。 In a solution with 30 or 40 projects, this can make it a lot easier to manage files. 在具有30或40个项目的解决方案中,这可以使管理文件变得更加容易。 For instance you can see that after modifying the file "ECR.h" the fact that it has been modified shows in both of the filter file listings (the small red check mark next to the name). 例如,您可以看到,在修改文件“ ECR.h”后,两个文件列表(名称旁边的小红色复选标记)都显示了已被修改的事实。

屏幕显示Visual Studio 2017解决方案资源管理器,显示在两个具有相同文件的项目中重复的相同过滤器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM