如何从c ++项目中获取AdditionalIncludeDirectories
的列表?
我在c#中编写了一个外接程序,用于查看C ++解决方案/项目,它需要这类信息,以及Visual Studio中的“INCLUDE”目录(我也遇到了问题) ,因为它们未在系统环境变量中列出。
是否有EnvDTE
(或VCProject
)选项可以为我提供AdditionalIncludeDirectories
或ProjectIncludeDir
?
答案 0 :(得分: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)");