In a VSPackage, getting services on startup

a few years back, I wrote a VSPackage that needs to get a reference to TFS VersionControlServer on startup.  However, this was problematic as Package.Initalize happens while the IDE is still in “Zombie” state.  To know when Zombie state is done, you hook OnShellPropertyChanged and listen for propid = __VSSPROPID_Zombie, val = False.  This worked fine in previous version of VS, but not VS2012, as it appeard TFS initializes later in the process.  To Solve this, I am now listening for propid = __VSSPROPID_ShellInitialized.

Private _shellPropertyChangeCookie As UInteger
Public Function OnShellPropertyChange(ByVal propid As Integer, ByVal var As Object) As Integer Implements IVsShellPropertyEvents.OnShellPropertyChange
    ' if the zombie state changes from true to false we can go ahead and
    ' ask for the DTE service and then stop listening for property change
    If propid = CInt(__VSSPROPID4.VSSPROPID_ShellInitialized) Then ' AndAlso CBool(var) = False Then
        Dim shellService As IVsShell = GetService(Of SVsShell, IVsShell)()
        If shellService IsNot Nothing Then
            _shellPropertyChangeCookie = 0
        End If


    End If

    Return Microsoft.VisualStudio.VSConstants.S_OK

End Function

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s