How to: Force a VSPackage to Load
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

How to: Force a VSPackage to Load

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:

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

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

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

© 2015 Microsoft