0

我正在研究一个针对C++项目的扩展。它需要检索项目的IncludePaths列表。在VS IDE中,它是菜单 - >项目 - >属性 - >配置属性 - > C++ - >常规 - >其他包含目录。这就是我需要在扩展程序中以编程方式获取的内容。什么类可以访问Visual Studio IDE中所谓的属性?

我有一个相应的VCProject实例,我也有一个VCConfiguration实例。从Automation Model Overview chart判断,项目和配置都有一组属性。但是,它们似乎并不可用。 VCConfiguration和VCProject类都没有任何属性集合,即使在运行时检查VCConfiguration和VCProject对象的内容。

MSDN docs也不提供任何见解。 VCConfiguration接口有一个属性PropertySheets,但在调试器的帮助下在运行时检查它后,我确定它不是我所需要的。

PS如果我只能得到命令行属性的值(项目 - >属性 - >配置属性 - > C++ - >命令行),参数列表的编译器将针对给定的项目调用 - 这也是很好,我可以解析该字符串以获取所有包含路径。

回答

1

你可能会想删除我的一些多余的废话...但是这应该做的伎俩:

public string GetCommandLineArguments(Project p) 
    { 
    string returnValue = null; 

    try 
    { 
     if ((Instance != null)) 
     { 
      Properties props = p.ConfigurationManager.ActiveConfiguration.Properties; 
      try 
      { 
       returnValue = props.Item("StartArguments").Value.ToString(); 
      } 
      catch 
      { 
       returnValue = props.Item("CommandArguments").Value.ToString(); 
       // for c++ 
      } 
     } 
    } 
    catch (Exception ex) 
    { 
     Logger.Info(ex.ToString()); 
    } 

    return returnValue; 
    } 

这些可能会有所帮助,也:(所以你可以看到什么性质的项目有和它们的值)

public void ShowProjectProperties(Project p) 
     { 
     try 
     { 
      if ((Instance != null)) 
      { 
       string msg = Path.GetFileNameWithoutExtension(p.FullName) + " has the following properties:" + Environment.NewLine + Environment.NewLine; 

       Properties props = p.ConfigurationManager.ActiveConfiguration.Properties; 
       List<string> values = props.Cast<Property>().Select(prop => SafeGetPropertyValue(prop)).ToList(); 
       msg += string.Join(Environment.NewLine, values); 
       MessageDialog.ShowMessage(msg); 
      } 
     } 
     catch (Exception ex) 
     { 
      Logger.Info(ex.ToString()); 
     } 
     } 

     public string SafeGetPropertyValue(Property prop) 
     { 
     try 
     { 
      return string.Format("{0} = {1}", prop.Name, prop.Value); 
     } 
     catch (Exception ex) 
     { 
      return string.Format("{0} = {1}", prop.Name, ex.GetType()); 
     } 
     } 
+0

这对您的问题有帮助吗? – Derek

相关问题