ProjectItems Interface
Assembly: EnvDTE (in envdte.dll)
This collection consists of a hierarchical (nested) structure of cascading ProjectItems collections that represent items in each project.
Reference this collection using Solution.Item().ProjectItems.
Note |
|---|
| In Visual Studio .NET 2003 and Visual Studio 2005, special handling for the Project.ProjectItems collection for Visual C++ is no longer required. That is, while the Visual C++ ProjectItems collection previously stored all Visual C++ project files in a flat list, now the files are stored hierarchically as they are in the other programming languages. |
Since this change can affect your existing code, there is a way to emulate the old behavior in the new project-specific object model when trying to index the Project.ProjectItems collection to determine whether or not a file is in the project. The primary difference is that you can now return to the DTE object model by calling .Object on a Visual C++ object.
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
Note