Automatically Loading VSIX Packages

So you’re creating a VSIX package that does not have a menu items, tool windows or command? But still you want the package to get loaded (i.e. executed) by the IDE? What a crazy thing to wish for, one might think after spending hours searching the internet on how to do that. But don’t abandon hope, yet, since the answer is nigh.

If you want to, you can check out the original article at MSDN, but the short answer is use the ProvideAutoLoadAttribute to annotate you package. In addition, use the VSConstants class along with its nested class UICONTEXT to define the visual studio context where the package will automatically be loaded.

Example:

[PackageRegistration(UseManagedResourcesOnly = true, RegisterUsing = RegistrationMethod.Assembly)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[Guid(GuidList.guidDebuggerAutoAttachPkgString)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_string)]
public sealed class MyTopnotchPackage : Package
{
    // maybe you'd want some code inside here...
}
Advertisements

One thought on “Automatically Loading VSIX Packages

  1. Perfect. I have a package with a menu item with dynamic visibility and default of invisible. Without this attribute (ProvideAutoLoad) the package never loads. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s