0

How can I get a list of the AdditionalIncludeDirectories from a c++ project ?

I am writing an Add-in, in c#, that looks at a C++ solution/ project, and it requires this type of information, as well as the "INCLUDE" directories from Visual Studio (which I am also having trouble getting, because they are not listed in the System Environment Variables).

Is there an EnvDTE (or VCProject) option that can give me the AdditionalIncludeDirectories, or ProjectIncludeDir ?

Thalia
  • 13,637
  • 22
  • 96
  • 190

1 Answers1

2

In add-in for VS2012 you can get AdditionalIncludeDirectories by doing the following (note that this is per project configuration rather than per project):

You need to add reference to the "Microsoft.VisualStudio.VCProjectEngine" assembly.

using Microsoft.VisualStudio.VCProjectEngine;

EnvDTE.Project project = null; // You get this project from somewhere
VCProject vcProject = project.Object as VCProject;
IEnumerable projectConfigurations = vcProject.Configurations as IEnumerable;
foreach (Object objectProjectConfig in projectConfigurations)
{
    VCConfiguration vcProjectConfig = objectProjectConfig as VCConfiguration;
    IEnumerable projectTools = vcProjectConfig.Tools as IEnumerable;
    foreach (Object objectProjectTool in projectTools)
    {
        VCCLCompilerTool compilerTool = objectProjectTool as VCCLCompilerTool;
        if (compilerTool != null)
        {
            string additionalIncludeDirs = compilerTool.AdditionalIncludeDirectories;
            break;
        }
    }
}

To get the <"INCLUDE" directories from Visual Studio> you can 'ask' configuration to evaluate the VS "IcludePath" variable:

string includeDirs = vcProjectConfig.Evaluate("$(IncludePath)");
Sergey
  • 111
  • 8