简体   繁体   English

C#Visual Studio SDK:VCDirectories界面

[英]C# Visual Studio SDK: VCDirectories interface

I am currently working on a Visual Studio addin in Visual Studio 2015 which will retrieve the global include/library directories relevant to a loaded Visual C++ project. 我目前正在Visual Studio 2015中使用Visual Studio插件,它将检索与已加载的Visual C ++项目相关的全局include / library目录。

According to the Microsoft Documentation , the VCDirectories interface exists as a member of the Microsoft.VisualStudio.VCProject namespace. 根据Microsoft文档VCDirectories接口作为Microsoft.VisualStudio.VCProject命名空间的成员存在。 However, I am having trouble accessing this interface when I have a valid VCProject reference in scope. 但是,当我在作用域中有有效的VCProject引用时,无法访问此接口。

public List<string> IncludeDirectories()
{
  List<string> includeDirs = new List<string>();

  // assume VCProj() returns a valid VCProject object
  VCProject proj = VCProj();
  VCDirectories dirs = proj.VCDirectories;

  return includeDirs;
}

From my understanding of the documentation, I should be able to reference the VCDirectories via proj in the snippet above. 从对文档的理解来看,我应该能够通过上面的片段中的proj引用VCDirectories。 But the VCDirectories interface does not exist. 但是VCDirectories接口不存在。

The full error reported by Visual Studio is; Visual Studio报告的完整错误为; 'VCProject' does not contain a definition for 'VCDirectories' and no extension method 'VCDirectories' accepting a first argument of type 'VCProject' could be found (are you missing a using directive or an assembly reference?) . 'VCProject' does not contain a definition for 'VCDirectories' and no extension method 'VCDirectories' accepting a first argument of type 'VCProject' could be found (are you missing a using directive or an assembly reference?)

Can someone show me where I am going wrong? 有人可以告诉我我要去哪里了吗?

Cheers 干杯

Edit 编辑

To complete the function above using information provided by Carlos; 要使用卡洛斯提供的信息来完成上述功能;

public List<string> IncludeDirectories()
{
  List<string> includeDirs = new List<string>();

  // assume VCProj() returns a valid VCProject object
  VCProject proj = VCProj();
  VCPlatform pf = proj.ActiveConfiguration.Platform;
  string[] directories = pf.Evalualte(pf.IncludeDirectories).split(';');

  foreach(string dir in directories) {
    if(dir != "") {
      includeDirs.Add(dir);
    }
  }

  return includeDirs;
}

You may want to use instead the following properties: 您可能需要使用以下属性:

You can get the VCPlatform as I shown in the approach of this article some years ago: 正如几年前我在本文中所展示的那样,您可以获得VCPlatform:

HOWTO: Get standard include directories of Visual C++ project from an add-in HOWTO:从加载项获取Visual C ++项目的标准包含目录

You can get the VCCLCompilerTool with the approach of this other article: 您可以通过本文的另一种方法获得VCCLCompilerTool:

HOWTO: Get additional include directories of Visual C++ project from an add-in HOWTO:从外接程序获取Visual C ++项目的其他包含目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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