ProjectItems 介面

更新:2007 年 11 月

包含 ProjectItem 物件,每一個物件都代表專案中的項目。

命名空間:  EnvDTE
組件:  EnvDTE (在 EnvDTE.dll 中)

語法

<GuidAttribute("8E2F1269-185E-43C7-8899-950AD2769CCF")> _
Public Interface ProjectItems _
    Implements IEnumerable

Dim instance As ProjectItems
[GuidAttribute("8E2F1269-185E-43C7-8899-950AD2769CCF")]
public interface ProjectItems : IEnumerable
[GuidAttribute(L"8E2F1269-185E-43C7-8899-950AD2769CCF")]
public interface class ProjectItems : IEnumerable
public interface ProjectItems extends IEnumerable

備註

這個集合由串聯 ProjectItems 集合 (代表每個專案中的項目) 的階層式 (巢狀) 結構組成。

請使用 Solution.Item().ProjectItems 參考這個集合。

注意事項:

在 Visual Studio .NET 2003 和 Visual Studio 2005 中,不再需要對 Visual C++ 的 Project.ProjectItems 集合進行特殊處理。也就是說,先前 Visual C++ ProjectItems 集合將所有的 Visual C++ 專案檔案儲存於平面圖式的清單,現在這些檔案會像在其他程式語言中一樣以階層式的方式儲存。

由於這個變更會影響現有的程式碼,在嘗試為 Project.ProjectItems 集合加上索引以判斷某檔案是否位於該專案時,有一種方法可以在新的專案特定物件模型中模擬舊有行為。主要的不同處是,您現在可以藉由呼叫 Visual C++ 物件中的 .Object,回到 DTE 物件模型。

Dim proj as VCProject = DTE.ActiveSolutionProjects(0).Object
Dim fileColl as IVCCollection = proj.Files
Dim file as VCFile = fileColl.Item("MyFile.cpp")
Dim projItem as ProjectItem = file.Object

範例

' Before running, create a new project or open an existing project.
Sub ListProj()
   Dim proj As Project = DTE.ActiveSolutionProjects(0)
   Dim win As Window = _
     DTE.Windows.Item(Constants.vsWindowKindCommandWindow)
   ListProjAux(proj.ProjectItems(), 0)
End Sub

Sub ListProjAux(ByVal projitems As ProjectItems, ByVal Level As Integer)
   Dim projitem As ProjectItem
   For Each projitem In projitems
      MsgBox("Project item: " & projitem.Name, Level)
      ' Recurse if the project item has sub-items...
      Dim projitems2 As ProjectItemsprojitems2 = projitem.ProjectItems
      Dim notsubcoll As Boolean = projitems2 Is Nothing
      If Not notsubcoll Then
         ListProjAux(projitems2, Level + 1)
      End If
   Next
End Sub

請參閱

參考

ProjectItems 成員

EnvDTE 命名空間

其他資源

控制專案與方案

HOW TO:編譯和執行 Automation 物件模型程式碼範例