Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

VSMacro get items in SolutionFolder

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim Hudson - 22 Feb 2008 16:24 GMT
I have a VSMacro that searches for all of the Projects in a Solution, so that
it can perform some processing for each Project.  Recently, one of the
developers on my team created some Solution Folders in the Solution, and
moved some of the Projects into those Solution Folders.

My current code does the following:

  For Each project As Project In DTE.Solution.Projects
       .
       .
  Next

As I watch it run in the VS Macro Editor, I see that project ends up
corresponding to each of the SolutionFolders, but never to any of the
Projects INSIDE those SolutionFolders.  I enhanced my VS Macro as follows:

  For Each project As Project In DTE.Solution.Projects
    If (project.Kind = EnvDTE80.ProjectKinds.vsProjectKindSolutionFolder)
Then
       <WHAT TO DO, HERE?>
    Else
       <process a regular Project>
    End If
  Next

However, I can't figure out what to do with the SolutionFolder "project".  
It has some stuff in its ProjectItems collection, but I don't know what they
are.

How do I enumerate the list of Projects inside a SolutionFolder?

Signature

Jim Hudson

Wen Yuan Wang [MSFT] - 25 Feb 2008 12:15 GMT
Hello Jim,

It seems you need to enumerate the list of projects inside solution folder.
Once you have a solution folder with items located within that folder, you
can use the folder as a Project object to locate an item contained within
it.

For example, suppose you have a solution folder with a project loaded into
it. The following macro finds the Project for the solution folder and then
obtains the collection of ProjectItems for the solution folder. Even though
a project within a solution folder is a project, it is still an item, and
so the solution folder allows you to get to a list of ProjectItem objects
by using the ProjectItems property. Once you have this ProjectItem object,
you can call the Object property to retrieve the object specific to that
project item node, which is a project.

Sub EnumProject()
       For Each project As Project In DTE.Solution.Projects
           If (project.Kind =
EnvDTE80.ProjectKinds.vsProjectKindSolutionFolder) Then

               For Each projItem As ProjectItem In project.ProjectItems
                   Dim containedProject As Project = projItem.Object
                   MsgBox(containedProject.Name)
               Next

           End If
       Next
   End Sub

Please try the above code and let me know if you have any more concern. We
are glad to assist you.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Jim Hudson - 25 Feb 2008 17:49 GMT
Thanks, Wen Yuan!  I had guessed nearly the code you show below, except I
left out the ".Object" from:

     Dim containedProject As Project = projItem.Object

Your code worked like a charm.  Thank you very much!

Signature

Jim Hudson

> Hello Jim,
>
[quoted text clipped - 36 lines]
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
Wen Yuan Wang [MSFT] - 26 Feb 2008 07:49 GMT
Welcome, Jim.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.