Ver versión en español    
 
Home
10 Reasons to use MZ-Tools
MZ-Tools 6.0 for VS.NET
Editions
Features
Online Documentation
MZ-Tools SDK
Download
Purchase
Version History (RSS)  
FAQ & Support
MZ-Tools 3.0 for VB6 & VBA
Features
Online Documentation
Download (freeware)
Donations (Paypal)
Version History (RSS)  
FAQ & Support
User Reviews
Community Place
Contact  
For Add-In Developers
About
   
 
User Testimonials

I'm an avid supporter of MZ-Tools. It's a product I couldn't do without and your level of support is outstanding.

Jan Hyde (Visual Basic MVP)

You will soon wonder how you ever lived without it.

Andy Maggs

More user reviews
 
BUG: ProjectItem.Collection returns a wrong collection for folders of SQL Projects of Visual Studio Team Edition for Database Professionals

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2005
Date: September 2007  
     

Introduction

This article explains a bug in the EnvDTE.ProjectItem.Collection implementation of folders of SQL Server projects of the Visual Studio Team Edition for Database Professionals.

More Information

An EnvDTE.ProjectItem of a project can be a folder or a file. A folder can contain folders or files and a file can contain dependant files (such as .designer.cs or .resx). For that purpose, the EnvDTE.ProjectItem class of the automation model provides two properties:

  • ProjectItem.ProjectItems: this collection returns the children of the ProjectItem. It is used to navigate the hierarchy from top to bottom.
  • ProjectItem.Collection: this collection returns the collection of items the ProjectItem belongs to. In particular, the ProjectItem.Collection.Parent property returns the parent of the ProjectItem. It is used to navigate the hierarchy from bottom to top.

Due to a bug in the implementation of ProjectItem.Collection of folders of SQL Server projects, the collection returned is the same than ProjectItem.ProjectItems.

Steps to reproduce the problem:

  • Create a SQL Server 2005 database project, which contains by default the folders "Data Generation Plans", "Schema Objects" and "Scripts".
  • Execute this macro: 
Dim objProjectItemFolder As ProjectItem
Dim colParentCollection As ProjectItems

objProjectItemFolder = DTE.Solution.Projects.Item(1).ProjectItems.Item("Data Generation Plans")
colParentCollection = objProjectItemFolder.Collection

If colParentCollection.Count = 0 Then
  MsgBox("We should be 3 folders, not 0")
End If

The macro returns 0 folders because ProjectItem.Collection is actually returning the children of the folder, which are zero.

A consequence of this bug is that since ProjectItem.Collection.Parent returns itself, you can enter in an infinite recursion if you try to navigate the hierarchy of files and folders from bottom to top.

Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this

MZ-Tools 6.0 for Visual Studio .NET

You can code, design, locate code and document your apps much faster using VB.NET, C#, C++ or Visual J#:

Buy MZ-Tools Now Download MZ-Tools Demo

   Top