如何以编程方式获取 VC++ 包含目录?
How to get VC++ include directories programmatically?
我正在用 C# 编写 Visual Studio 扩展,我需要获取项目属性。更具体地说,我正在寻找一个 API 允许获得 "Configuration Properties > VC++ Directories > Include directories" 的 扩展值 ,或者如何获得 $(VC_IncludePath) 或 $(WindowsSDK_IncludePath).更一般地说,如何获得由 IDE 或编译器设置的任何变量的 扩展值 。
我可以找到一些 posts 告诉如何获取 vcxproj 文件中存在的属性(来自 IVsSolution 和 IVsBuildPropertyStorage)。但是,我正在寻找的这些属性似乎是由 IDE 或编译器设置的,并且不存在于 vcxproj 文件中。我找不到任何关于那个的 post 。
更一般地说,我需要得到扩展值:
- 配置属性 > 常规 > 项目默认值 > 配置类型
- 配置属性 > VC++ 目录 > 包含目录
- 配置属性 > C/C++ > 常规 > 附加包含目录
- 配置属性 > C/C++ > 常规 > 其他 #using 目录
- 配置属性 > C/C++ > 预处理器 > 预处理器定义
- 配置属性 > C/C++ > 预处理器 > 取消定义预处理器定义
- 配置属性 > C/C++ > 预处理器 > 取消定义所有预处理器定义
- 配置属性 > C/C++ > 预处理器 > 忽略标准包含路径
- 配置属性 > NMake > IntelliSense > 预处理器定义
- 配置属性 > NMake > IntelliSense > 包括搜索路径
请注意,Project.ConfigurationManager.ActiveConfiguration.Properties 在我的案例中为空。成功通过VCProject.ActiveConfiguration.
Solution:
Thanks to @Lance hints, I ended up to the global C++ Project Configuration documentation page: https://docs.microsoft.com/en-us/cpp/build/reference/property-pages-visual-cpp. It gives the ways to access to the different configuration settings I was looking for. Plus all specific links mentioned by Lance in his answer.
How to get VC++ include directories programmatically?
你可以用VSPlatform.IncludeDirectories属性来得到你想要的。 (我们需要通过右击项目=>添加引用=>扩展引用手动添加对Microsoft.VisualStudio.VCProjectEngine.dll
的引用...)
并且对于那些属性,例如 AdditionalIncludeDirectories , AdditionalUsingDirectories , PreprocessorDefinitions... under C/C++
tab you can use VCCLCompilerTool 访问它们的接口。
对于 NMake
选项卡下的属性,使用 VCNMakeTool.IncludeSearchPath and VCNMakeTool.PreprocessorDefinitions 访问它们。
此外:您可以从 Carlos J、one and two 的这两个博客中获得帮助。感谢他!
更新1:
来自 VS SDK
的那些 api 或属性用于获取我们在 VS UI
中看到的值:
我们可以在 VS 中看到 $(...) UI,我们可以使用上面的那些属性来使用 VS SDK 获取它们。这些属性 return 宏如 $(VC_IncludePath)
是预期的行为...要获得 $(VC_IncludePath)
的扩展值,这不是 VS SDK 的工作,它是 MSBuild scope 因为宏是由 msbuild 目标和道具文件定义和导入。
我正在用 C# 编写 Visual Studio 扩展,我需要获取项目属性。更具体地说,我正在寻找一个 API 允许获得 "Configuration Properties > VC++ Directories > Include directories" 的 扩展值 ,或者如何获得 $(VC_IncludePath) 或 $(WindowsSDK_IncludePath).更一般地说,如何获得由 IDE 或编译器设置的任何变量的 扩展值 。
我可以找到一些 posts 告诉如何获取 vcxproj 文件中存在的属性(来自 IVsSolution 和 IVsBuildPropertyStorage)。但是,我正在寻找的这些属性似乎是由 IDE 或编译器设置的,并且不存在于 vcxproj 文件中。我找不到任何关于那个的 post 。
更一般地说,我需要得到扩展值:
- 配置属性 > 常规 > 项目默认值 > 配置类型
- 配置属性 > VC++ 目录 > 包含目录
- 配置属性 > C/C++ > 常规 > 附加包含目录
- 配置属性 > C/C++ > 常规 > 其他 #using 目录
- 配置属性 > C/C++ > 预处理器 > 预处理器定义
- 配置属性 > C/C++ > 预处理器 > 取消定义预处理器定义
- 配置属性 > C/C++ > 预处理器 > 取消定义所有预处理器定义
- 配置属性 > C/C++ > 预处理器 > 忽略标准包含路径
- 配置属性 > NMake > IntelliSense > 预处理器定义
- 配置属性 > NMake > IntelliSense > 包括搜索路径
请注意,Project.ConfigurationManager.ActiveConfiguration.Properties 在我的案例中为空。成功通过VCProject.ActiveConfiguration.
Solution: Thanks to @Lance hints, I ended up to the global C++ Project Configuration documentation page: https://docs.microsoft.com/en-us/cpp/build/reference/property-pages-visual-cpp. It gives the ways to access to the different configuration settings I was looking for. Plus all specific links mentioned by Lance in his answer.
How to get VC++ include directories programmatically?
你可以用VSPlatform.IncludeDirectories属性来得到你想要的。 (我们需要通过右击项目=>添加引用=>扩展引用手动添加对Microsoft.VisualStudio.VCProjectEngine.dll
的引用...)
并且对于那些属性,例如 AdditionalIncludeDirectories , AdditionalUsingDirectories , PreprocessorDefinitions... under C/C++
tab you can use VCCLCompilerTool 访问它们的接口。
对于 NMake
选项卡下的属性,使用 VCNMakeTool.IncludeSearchPath and VCNMakeTool.PreprocessorDefinitions 访问它们。
此外:您可以从 Carlos J、one and two 的这两个博客中获得帮助。感谢他!
更新1:
来自 VS SDK
的那些 api 或属性用于获取我们在 VS UI
中看到的值:
我们可以在 VS 中看到 $(...) UI,我们可以使用上面的那些属性来使用 VS SDK 获取它们。这些属性 return 宏如 $(VC_IncludePath)
是预期的行为...要获得 $(VC_IncludePath)
的扩展值,这不是 VS SDK 的工作,它是 MSBuild scope 因为宏是由 msbuild 目标和道具文件定义和导入。