简体   繁体   English

如何在 Visual Studio 中创建 C++ 项目过滤器/文件夹?

[英]How to Create C++ Project Filter/Folder in Visual Studio?

Using Visual Studio 2012, I'd like to create a C++ project folder called "Include Files", which has the same characteristics as the well known folder "Header Files".使用 Visual Studio 2012,我想创建一个名为“Include Files”的 C++ 项目文件夹,它与众所周知的文件夹“Header Files”具有相同的特征。 That is, the files in Include Files have a cpi extenson and will be parsed out for use with InteliSense, and also can be precompiled.也就是说,包含文件中的文件有一个 cpi 扩展,将被解析出来以用于 InteliSense,也可以被预编译。

I'm able to create the folder but files within it aren't parsed.我能够创建文件夹,但其中的文件没有被解析。 I've tried setting the type to C++ Header file.我试过将类型设置为 C++ 头文件。 Nothing seems to work.似乎没有任何效果。 The files work fine when given a hpp extension and put into Header Files folder.当给定 hpp 扩展名并放入 Header Files 文件夹时,这些文件可以正常工作。

If it is anything like VS2010 this is done from the Tools/Options/Text-Editor dialog options.如果是像 VS2010 这样的东西,这是从工具/选项/文本编辑器对话框选项中完成的。 Under the tree item "File Extensions" you can add custom file extensions and have them treated with the editing experience of your choice.在树项“文件扩展名”下,您可以添加自定义文件扩展名,并使用您选择的编辑体验处理它们。

To simulate your case I did the following:为了模拟您的情况,我执行了以下操作:

  1. Opened Tools/Options/Text-Editor option screen.打开工具/选项/文本编辑器选项屏幕。
  2. In the right pane, type "cpi" in the "Extension: box.在右侧窗格中,在“扩展名:”框中键入“cpi”。
  3. Select "Microsoft Visual C++" for the editor.为编辑器选择“Microsoft Visual C++”。
  4. Select Add/Apply to add this to the custom extensions list.选择添加/应用以将其添加到自定义扩展列表中。

Proceed as normal.照常进行。 Open any CPI file and it should now display with the same syntax highlighting, and IntelliSense options, as any c/cpp/h/hpp, etc file.打开任何 CPI 文件,它现在应该以与任何 c/cpp/h/hpp 等文件相同的语法突出显示和 IntelliSense 选项显示。

At least thats how I do it with my custom file extensions.至少这就是我使用自定义文件扩展名的方式。 It sounds like you have the filtering into subfolders the way you want it already.听起来您已经按照您想要的方式过滤到子文件夹中。

Here's some raw information about how I implemented, CPI , the custom file extension similar in purpose to .h.这里有一些关于我如何实现的原始信息, CPI ,目的类似于 .h 的自定义文件扩展名。 My task was to create a program that dynamically creates Visual Studio 2012 C++ solutions and projects.我的任务是创建一个动态创建 Visual Studio 2012 C++ 解决方案和项目的程序。 This was needed because VS templates don't work with C++, only with .Net.这是必需的,因为 VS 模板不适用于 C++,只能用于 .Net。

I created a Visual Basic script file to create solution and project files.我创建了一个 Visual Basic 脚本文件来创建解决方案和项目文件。 It inserted the following XML into a custom vcxproj file.它将以下 XML 插入到自定义 vcxproj 文件中。 There are XML tags other than None such as ClCompile or Include.除了None ,还有其他 XML 标记,例如 ClCompile 或 Include。 The None tag seems to work for my purposes; None标签似乎对我有用; enables parsing, Intellisense, and context menu options.启用解析、智能感知和上下文菜单选项。

   <ItemGroup>
        [Do following pattern for each CPI file]
        <None Include="MyCPI.CPI">
            <FileType>CppHeader</FileType>
        </None>
    </ItemGroup>

I created the following XML and inserted into the vcxproj.filters files:我创建了以下 XML 并插入到 vcxproj.filters 文件中:

[Insert within ItemGroup at beginning of file. [在文件开头的 ItemGroup 中插入。 The GUID is the same as C++ Header Files. GUID 与 C++ 头文件相同。 I'm not sure what that means.]我不确定这意味着什么。]

<Filter Include="Include Files">
      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
      <Extensions>cpi</Extensions>
</Filter>

<ItemGroup>
    [Do following pattern for each CPI file]
    <None Include="MyCPI.CPI">
        <Filter>++Include Files</Filter>
    </None>
</ItemGroup>

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

相关问题 c ++ visual studio 2010-如何在其他文件夹名称下创建项目? - c++ visual studio 2010 - How to create a project under a different folder name? 如何在 Visual Studio 中打开 C++ 项目文件夹? - How do I open a c++ project folder in visual studio? 如何在Visual Studio C ++ 2012中创建文件夹 - How to create a folder in Visual Studio C++ 2012 如何创建Visual Studio 2008 C ++项目模板? - How to create a Visual Studio 2008 C++ project template? 如何在visual studio 2010中创建非托管c ++项目? - How to create unmanaged c++ project in visual studio 2010? C ++ / Visual Studio-_wgetcwd返回项目文件夹而不是应用程序 - C++/Visual Studio - _wgetcwd returns project folder not application 将具有子文件夹层次结构的文件夹添加到Visual Studio C ++ 2015项目 - Add folder with subfolders hierarchy to visual studio c++ 2015 project 如何在Visual Studio 2017中创建Visual c ++ MFC控制台项目 - How to create a Visual c++ MFC console project in visual studio 2017 如何为C ++创建Visual Studio DebuggerVisualizer - How to create Visual Studio DebuggerVisualizer for C++ 如何在 Visual Studio 的 c++ 项目中使用 c++.dll - How to use a c++ .dll in a c++ project in visual studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM