Some clarity on auto loading Visual Studio 2010 Extensions
Visual Studio 2010 Extensions (VSIX) are great for adding the functionality you need to Visual Studio 2010. With an SDK, easy-to-understand API, support for WPF and tons of examples (http://code.msdn.microsoft.com/vsx) it’s also a great platform for developers.
In most cases you’ll want to build an extension that does something when you click a button, when you type something, … and this is also the default behavior of your package. The method Initialize() will only be invoked when your action triggers it. So don’t worry if Initialize() doesn’t get called when Visual Studio starts because this is default behavior.
But what if you want Initialize() to be called when Visual Studio starts? In previous versions of Visual Studio you had the RegisterAutoLoadAttribute which has now been made obsolete.
Auto loading with ProvideAutoLoadAttribute
Visual Studio 2010 comes with this new attribute, the ProvideAutoLoadAttribute. If you decorate your Package with this attribute you’ll be able to configure the auto loading process. Here’s an example of how you can configure this:
[ProvideAutoLoad("ADFC4E64-0397-11D1-9F4E-00A0C911004F")] public sealed class MyPackage : Package
The attribute requires you to pass a Guid. This Guid stands for the context in which you want your extension to start. In the following listyou can find a list of all available contexts:
- UICONTEXT_CodeWindow: 8FE2DF1D-E0DA-4EBE-9D5C-415D40E487B5
Specifies a UI context in which the code window is active.
- UICONTEXT_Debugging: ADFC4E61-0397-11D1-9F4E-00A0C911004F
Specifies The UI context for debugging mode.
- UICONTEXT_DesignMode: ADFC4E63-0397-11D1-9F4E-00A0C911004F
Specifies the UI context for design mode.
- UICONTEXT_Dragging: B706F393-2E5B-49E7-9E2E-B1825F639B63
Specifies a UI context in which a drag/drop operation is active.
- UICONTEXT_EmptySolution: ADFC4E65-0397-11D1-9F4E-00A0C911004F
Specifies a UI context in which an empty solution is active.
- UICONTEXT_FullScreenMode: ADFC4E62-0397-11D1-9F4E-00A0C911004F
Specifies a UI context in which the Full Screen mode of the view is active.
- UICONTEXT_NoSolution: ADFC4E64-0397-11D1-9F4E-00A0C911004F
Specifies a UI context in which no solution is open.
- UICONTEXT_SolutionBuilding: ADFC4E60-0397-11D1-9F4E-00A0C911004F
Specifies a UI context in which the solution is being built.
- UICONTEXT_SolutionExists: F1536EF8-92EC-443C-9ED7-FDADF150DA82
Specifies a UI context in which a solution exists.
- UICONTEXT_SolutionHasMultipleProjects: 93694FA0-0397-11D1-9F4E-00A0C911004F
Specifies a UI context in which a solution is open and has multiple projects loaded.
- UICONTEXT_SolutionHasSingleProject: ADFC4E66-0397-11D1-9F4E-00A0C911004F
Specifies a UI context in which a solution with a single project is open.