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

相關問題