Export (0) Print
Expand All

How to: Force a VSPackage to Load (C#)

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

VSPackages are ordinarily loaded only when their accompanying functionality is required to complete a process. Under some circumstances, however, a VSPackage may have to force another VSPackage to be loaded. For example, a lightweight VSPackage might load a larger VSPackage in a programming context that is not available as a CMDUIContext.

You can use the LoadPackage method to force a VSPackage to load.

To force a VSPackage to load

  • Insert this code into the Initialize method of the VSPackage that forces another VSPackage to load:

    Dim shell As IVsShell = TryCast(GetService(GetType(SVsShell)), IVsShell)
    If shell Is Nothing Then
    Return
    End If
    
    Dim package As IVsPackage = Nothing
    Dim PackageToBeLoadedGuid As Guid = GetType(PackageToBeLoaded).GUIDshell.LoadPackage(PackageToBeLoadedGuid, package)
    

    IVsShell shell = GetService(typeof(SVsShell)) as IVsShell;
    if (shell == null) return;
    
    IVsPackage package = null;
    Guid PackageToBeLoadedGuid = typeof(PackageToBeLoaded).GUID;
    shell.LoadPackage(ref PackageToBeLoadedGuid, out package);
    
    

    When the VSPackage is initialized, it will force PackageToBeLoaded to load.

Robust Programming

Force loading should not be used for VSPackage communication. Use Services instead.

See Also

Concepts

Loading VSPackages

Other Resources

VSPackages

Community Additions

ADD
Show:
© 2015 Microsoft