简体   繁体   中英

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". 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.

I'm able to create the folder but files within it aren't parsed. I've tried setting the type to C++ Header file. Nothing seems to work. The files work fine when given a hpp extension and put into Header Files folder.

If it is anything like VS2010 this is done from the Tools/Options/Text-Editor dialog options. 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.
  3. Select "Microsoft Visual C++" for the editor.
  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.

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. My task was to create a program that dynamically creates Visual Studio 2012 C++ solutions and projects. This was needed because VS templates don't work with C++, only with .Net.

I created a Visual Basic script file to create solution and project files. It inserted the following XML into a custom vcxproj file. There are XML tags other than None such as ClCompile or Include. The None tag seems to work for my purposes; 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:

[Insert within ItemGroup at beginning of file. The GUID is the same as C++ Header Files. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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