INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

HANDLE


PASSWORD
Remember Me
Forgot Password?

Come Join Us!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • Turn Off Ad Banners
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

E-mail*
Handle

Password
Verify P'word
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Member Feedback

"...Keep up the good work - excellent site - i'd been looking for something like this for ages !..."

Geography

Where in the world do Tek-Tips members come from?

Visual Basic(Microsoft) -VB.NET 2002-2008 FAQ

How-to

Get Project information from EnvDTE at Design time
Posted: 22 Jan 07

Hello all,

I was working on some code and needed to access Project information at design time. It was a real struggle to find any documentation on how to do that. Below is a method I wrote which help me get started.

A. I put this code inside a Designer class because I needed to use GetService and Component.Site provides a GetService method

B. You will need to set a reference to envdte for the code to work.

CODE

Public Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
    Try
        Dim visualStudioIDE As EnvDTE.DTE = _
            CType(component.Site.GetService(GetType(EnvDTE.DTE)), EnvDTE.DTE)
        If visualStudioIDE Is Nothing Then Throw New InvalidOperationException("DTE not found.")
        Dim o, projects, mainWindow As Object
        Dim ad As EnvDTE.Document
        Dim aw As EnvDTE.Window
        Dim docs As EnvDTE.Documents
        Dim mode As EnvDTE.vsIDEMode
        Dim solution As EnvDTE.Solution
        Dim windows As EnvDTE.Windows
        With visualStudioIDE
            ad = .ActiveDocument
            projects = .ActiveSolutionProjects
            aw = .ActiveWindow
            docs = .Documents
            o = .GetObject("VBProjects")
            mode = .Mode
            mainWindow = .MainWindow
            solution = .Solution
            windows = .Windows
        End With

        Dim text As String
        For Each [property] As EnvDTE.Property In aw.Project.Properties
            text &= [property].Name & " " & [property].Value.ToString & vbNewLine
        Next
        MsgBox(text, MsgBoxStyle.Information)
        Console.WriteLine("")
        Console.WriteLine(text)

        text = String.Empty
        For Each item As EnvDTE.ProjectItem In aw.Project.ProjectItems
            text &= item.Name & " " & item.FileNames(0) & vbNewLine
        Next
        MsgBox(text, MsgBoxStyle.Information)
        Console.WriteLine("")
        Console.WriteLine(text)

    Catch ex As Exception
        Throw
    End Try
End Sub 'Initialize
Enjoy...

Back to Visual Basic(Microsoft) -VB.NET 2002-2008 FAQ Index
Back to Visual Basic(Microsoft) -VB.NET 2002-2008 Forum
My FAQ Archive
Email This FAQ To A Friend

My Archive