Udostępnij za pośrednictwem


How to: Autoload a VSPackage (C#)

VSPackages can be set to autoload when a particular user interface (UI) context exists. For example, a VSPackage can be set to load whenever a solution exists. The managed package framework (MPF) provides the ProvideAutoLoadAttribute attribute to set this context.

To set the UI context to autoload a VSPackage

  • Add the ProvideAutoLoad attribute to the VSPackage attributes:

    [MsVsShell.DefaultRegistryRoot
       (@"Software\Microsoft\VisualStudio\8.0Exp")]
    [MsVsShell.PackageRegistration
       (UseManagedResourcesOnly = true)]
    [MsVsShell.ProvideAutoLoad 
       ("{f1536ef8-92ec-443c-9ed7-fdadf150da82}")]
    [Guid("2DB4D57F-746A-47df-AC04-81517556A929")]
    public class MyAutoloadedPackage : MsVsShell.Package
    {
    

    Note

    You must pass the GUID value of UICONTEXT_SolutionExists to ProvideAutoLoad instead of its symbolic name. See the enumerated fields of VSConstants for a list of the UI contexts and their GUID values.

To autoload the VSPackage

  1. Set a breakpoint in the Initialize method.

  2. Build the VSPackage and start it from the debugger by pressing F5.

  3. Load a solution or create a new one.

    The VSPackage loads and stops at the breakpoint.

See Also

Concepts

Loading VSPackages

Other Resources

VSPackages