0

如何AdditionalIncludeDirectories从 c++ 项目中获取列表?

我正在用 c# 编写一个加载项,它查看一个 C++ 解决方案/项目,它需要这种类型的信息,以及 Visual Studio 中的“INCLUDE”目录(我也很难获取,因为它们未在系统环境变量中列出)。

是否有EnvDTE(或VCProject)选项可以给我AdditionalIncludeDirectories, 或 ProjectIncludeDir

4

1 回答 1

2

在 VS2012 的加载项中,您可以通过执行以下操作来获取 AdditionalIncludeDirectories(请注意,这是每个项目配置而不是每个项目):

您需要添加对“Microsoft.VisualStudio.VCProjectEngine”程序集的引用。

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;
        }
    }
}

要从 Visual Studio 获取 <"INCLUDE" 目录>,您可以“询问”配置以评估 VS“IcludePath”变量:

string includeDirs = vcProjectConfig.Evaluate("$(IncludePath)");
于 2013-08-07T03:56:40.970 回答