How to: Autoload a VSPackage
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:
<DefaultRegistryRoot("Software\Microsoft\VisualStudio\10.0")> _ <PackageRegistration(UseManagedResourcesOnly:=True)> _ <ProvideAutoLoad(UIContextGuids80.SolutionExists)> _ <Guid("2DB4D57F-746A-47df-AC04-81517556A929")> _ Public Class MyAutoloadedPackage Inherits Package
[DefaultRegistryRoot(@"Software\Microsoft\VisualStudio\10.0")] [PackageRegistration(UseManagedResourcesOnly = true)] [ProvideAutoLoad(UIContextGuids80.SolutionExists)] [Guid("2DB4D57F-746A-47df-AC04-81517556A929")] public class MyAutoloadedPackage : Package
Note
See the enumerated fields of UIContextGuids80 for a list of the UI contexts and their GUID values.
To autoload the VSPackage
Set a breakpoint in the Initialize method.
Build the VSPackage and start it from the debugger by pressing F5.
Load a solution or create one.
The VSPackage loads and stops at the breakpoint.