Share via


Package Class

Definition

This class implements IVsPackage. It provides a framework-friendly way to define a package and its associated services.

public ref class Package abstract : IServiceProvider, Microsoft::VisualStudio::OLE::Interop::IOleCommandTarget, Microsoft::VisualStudio::OLE::Interop::IServiceProvider, Microsoft::VisualStudio::Shell::Interop::IVsPackage, Microsoft::VisualStudio::Shell::Interop::IVsPersistSolutionOpts, Microsoft::VisualStudio::Shell::Interop::IVsToolboxItemProvider, Microsoft::VisualStudio::Shell::Interop::IVsToolWindowFactory, Microsoft::VisualStudio::Shell::Interop::IVsUserSettings, Microsoft::VisualStudio::Shell::Interop::IVsUserSettingsMigration, Microsoft::VisualStudio::Shell::Interop::IVsUserSettingsQuery, System::ComponentModel::Design::IServiceContainer
public ref class Package abstract : IServiceProvider, Microsoft::VisualStudio::OLE::Interop::IOleCommandTarget, Microsoft::VisualStudio::OLE::Interop::IServiceProvider, Microsoft::VisualStudio::Shell::Interop::IVsPackage, Microsoft::VisualStudio::Shell::Interop::IVsPersistSolutionOpts, Microsoft::VisualStudio::Shell::Interop::IVsToolboxItemProvider, Microsoft::VisualStudio::Shell::Interop::IVsToolboxItemProvider2, Microsoft::VisualStudio::Shell::Interop::IVsToolWindowFactory, Microsoft::VisualStudio::Shell::Interop::IVsUserSettings, Microsoft::VisualStudio::Shell::Interop::IVsUserSettingsMigration, Microsoft::VisualStudio::Shell::Interop::IVsUserSettingsQuery, System::ComponentModel::Design::IServiceContainer
[Microsoft.VisualStudio.Shell.PackageRegistration]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Package : IServiceProvider, Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget, Microsoft.VisualStudio.OLE.Interop.IServiceProvider, Microsoft.VisualStudio.Shell.Interop.IVsPackage, Microsoft.VisualStudio.Shell.Interop.IVsPersistSolutionOpts, Microsoft.VisualStudio.Shell.Interop.IVsToolboxItemProvider, Microsoft.VisualStudio.Shell.Interop.IVsToolWindowFactory, Microsoft.VisualStudio.Shell.Interop.IVsUserSettings, Microsoft.VisualStudio.Shell.Interop.IVsUserSettingsMigration, Microsoft.VisualStudio.Shell.Interop.IVsUserSettingsQuery, System.ComponentModel.Design.IServiceContainer
[Microsoft.VisualStudio.Shell.PackageRegistration]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Package : IServiceProvider, Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget, Microsoft.VisualStudio.OLE.Interop.IServiceProvider, Microsoft.VisualStudio.Shell.Interop.IVsPackage, Microsoft.VisualStudio.Shell.Interop.IVsPersistSolutionOpts, Microsoft.VisualStudio.Shell.Interop.IVsToolboxItemProvider, Microsoft.VisualStudio.Shell.Interop.IVsToolboxItemProvider2, Microsoft.VisualStudio.Shell.Interop.IVsToolWindowFactory, Microsoft.VisualStudio.Shell.Interop.IVsUserSettings, Microsoft.VisualStudio.Shell.Interop.IVsUserSettingsMigration, Microsoft.VisualStudio.Shell.Interop.IVsUserSettingsQuery, System.ComponentModel.Design.IServiceContainer
[Microsoft.VisualStudio.Shell.PackageRegistration]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Package : IServiceProvider, Microsoft.VisualStudio.OLE.Interop.IOleCommandTarget, Microsoft.VisualStudio.OLE.Interop.IServiceProvider, Microsoft.VisualStudio.Shell.Interop.IVsAsyncUnifiedSettingsObserverFactory, Microsoft.VisualStudio.Shell.Interop.IVsPackage, Microsoft.VisualStudio.Shell.Interop.IVsPersistSolutionOpts, Microsoft.VisualStudio.Shell.Interop.IVsToolboxItemProvider, Microsoft.VisualStudio.Shell.Interop.IVsToolboxItemProvider2, Microsoft.VisualStudio.Shell.Interop.IVsToolWindowFactory, Microsoft.VisualStudio.Shell.Interop.IVsUserSettings, Microsoft.VisualStudio.Shell.Interop.IVsUserSettingsMigration, Microsoft.VisualStudio.Shell.Interop.IVsUserSettingsQuery, System.ComponentModel.Design.IServiceContainer
[<Microsoft.VisualStudio.Shell.PackageRegistration>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Package = class
    interface IVsPackage
    interface IServiceProvider
    interface IOleCommandTarget
    interface IVsPersistSolutionOpts
    interface IServiceContainer
    interface IServiceProvider
    interface IVsUserSettings
    interface IVsUserSettingsMigration
    interface IVsUserSettingsQuery
    interface IVsToolWindowFactory
    interface IVsToolboxItemProvider
[<Microsoft.VisualStudio.Shell.PackageRegistration>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Package = class
    interface IVsPackage
    interface IServiceProvider
    interface IOleCommandTarget
    interface IVsPersistSolutionOpts
    interface IServiceContainer
    interface IServiceProvider
    interface IVsUserSettings
    interface IVsUserSettingsMigration
    interface IVsUserSettingsQuery
    interface IVsToolWindowFactory
    interface IVsToolboxItemProvider
    interface IVsToolboxItemProvider2
[<Microsoft.VisualStudio.Shell.PackageRegistration>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Package = class
    interface IVsPackage
    interface IOleCommandTarget
    interface IVsPersistSolutionOpts
    interface IVsAsyncUnifiedSettingsObserverFactory
    interface IVsUserSettings
    interface IVsUserSettingsMigration
    interface IVsUserSettingsQuery
    interface IVsToolWindowFactory
    interface IVsToolboxItemProvider
    interface IVsToolboxItemProvider2
    interface IServiceProvider
    interface IServiceProvider
    interface IServiceContainer
Public MustInherit Class Package
Implements IOleCommandTarget, IServiceContainer, IServiceProvider, IServiceProvider, IVsPackage, IVsPersistSolutionOpts, IVsToolboxItemProvider, IVsToolWindowFactory, IVsUserSettings, IVsUserSettingsMigration, IVsUserSettingsQuery
Public MustInherit Class Package
Implements IOleCommandTarget, IServiceContainer, IServiceProvider, IServiceProvider, IVsPackage, IVsPersistSolutionOpts, IVsToolboxItemProvider, IVsToolboxItemProvider2, IVsToolWindowFactory, IVsUserSettings, IVsUserSettingsMigration, IVsUserSettingsQuery
Public MustInherit Class Package
Implements IOleCommandTarget, IServiceContainer, IServiceProvider, IServiceProvider, IVsAsyncUnifiedSettingsObserverFactory, IVsPackage, IVsPersistSolutionOpts, IVsToolboxItemProvider, IVsToolboxItemProvider2, IVsToolWindowFactory, IVsUserSettings, IVsUserSettingsMigration, IVsUserSettingsQuery
Inheritance
Package
Derived
Attributes
Implements

Remarks

The Package class provides a managed implementation of several of the most useful VSIP interfaces. You can create the basic functionality of a VSPackage with relatively little code by deriving from the Package class, overriding some of its methods, and attaching registration attribute classes. The Package class does not provide direct registration support, but it can use attribute classes to supply the necessary registration information to external tools such as RegPkg.exe.

The Package class offers the following services by default. (You can replace them by asking the VSPackage for IServiceContainer, removing them, and adding your own services in their place.)

  • Package

    The package offers itself as a service.

  • IServiceContainer

    Provides the ability to add and remove services. Any service added with "promote" set to true is proffered to Visual Studio through IProfferService. This makes the service global to all VSPackages within Visual Studio. (This service is available only if the VSPackage has already been loaded.)

In addition to these services, Package uses the service architecture of Visual Studio to provide access to any service available through the global service provider.

Constructors

Package()

Initializes a new instance of Package.

Properties

ApplicationRegistryRoot

Gets the root registry key of the current Visual Studio registry hive.

UserDataPath

Gets the path to user data storage for Visual Studio.

UserLocalDataPath

Returns the path to user data storage for Visual Studio. Typically this is %USERPROFILE%\Local Settings\Application Data
Visual Studio[ver] but this can change based on any alternate root that the shell was initialized with.

UserRegistryRoot

Returns the registry root for the current user. Typically this is HKCU\Software\Microsoft\VisualStudio[ver] but this can change based on any alternate root that the shell is initialized with. This key is read-write.

Zombied

Gets a value indicating whether the package in the process of shutdown.

Methods

AddOptionKey(String)

Adds a user option key name into the list of option keys.

CreateInstance(Guid, Guid, Type)

Create the specified COM object using Visual Studio's ILocalRegistry and cast it to the given managed type. If VS cannot create it, then fall back to Activator.CreateInstance. This allows managed classes to be registered in local to the particular VS version in HKLM\Software\Microsoft\VisualStudio\8.0\clsid.

CreateSettingsObserverAsync(Type, SettingsObserverArguments, CancellationToken)

Creates a settings observer object for the package. This method is called when unified settings are active, but only if the package has one or more ProvideSettingsObserverAttributes.

CreateTool(Guid)

Enables derived classes to provide an implementation if necessary.

CreateToolWindow(Guid, Int32)

Creates a tool window of the specified type with the specified ID.

CreateToolWindow(Type, Int32, Object)

Create a tool window of the specified type with the specified ID.

CreateToolWindow(Type, Int32, UInt32, Object, Guid)

Create a tool window of the specified type with the specified ID. This is the only method that should be calling IVsUiShell.CreateToolWindow()

CreateToolWindow(Type, Int32, UInt32)

Creates a tool window of the specified type with the specified ID.

CreateToolWindow(Type, Int32)

Creates a tool window of the specified type with the specified ID.

Dispose(Boolean)

Releases the resources used by the Package object.

FindToolWindow(Type, Int32, Boolean)

Gets the tool window corresponding to the specified type and ID.

FindWindowPane(Type, Int32, Boolean)

Gets the window pane corresponding to the specified type and ID, and if no window pane of that type exists creates one if told to do so.

GetAutomationObject(String)

Gets the automation object for the VSPackage.

GetDialogPage(Type)

Gets the requested dialog page.

GetGlobalService(Type)

Gets a service proffered globally by Visual Studio or one of its packages. This is the same as calling GetService() on an instance of a package that proffers no services itself.

GetOutputPane(Guid, String)

Gets the requested output window.

GetProviderLocale()

Returns the locale of the environment.

GetService(Type)

Gets type-based services from the VSPackage service container.

GetToolboxItemData(String, DataFormats+Format)

Gets the content of the data format for the specified toolbox item ID and data format.

GetToolboxItemDataAsync(String, DataFormats+Format)
Initialize()

Called when the VSPackage is loaded by Visual Studio.

InstantiateToolWindow(Type, Object)

Construct a tool window of the specified type.

InstantiateToolWindow(Type)
IsExperimentalInstance(IServiceProvider)
IsLocalService(Type)

Determines whether the specified service type can be retrieved without requiring an RPC transition to the UI thread.

OnLoadOptions(String, Stream)

Invoked by the package class when there are options to be read out of the solution file.

OnSaveOptions(String, Stream)

Invoked by the Package class when there are options to be saved to the solution file.

ParseToolboxResource(TextReader, Guid)

Parses an embedded text resource of appropriate format for information about which items should be added to the Toolbox.

ParseToolboxResource(TextReader, ResourceManager)

Parses an embedded text resource of appropriate format for information about which items should be added to the Toolbox.

QueryClose(Boolean)

Called to ask the package if the shell can be closed.

RegisterEditorFactory(IVsEditorFactory)

Registers an editor factory with Visual Studio.

RegisterProjectFactory(IVsProjectFactory)

Registers a project factory with Visual Studio.

ShowOptionPage(Type)

Displays a specified tools options page.

Events

ToolboxInitialized

Event generated whenever Visual Studio initializes its Toolbox.

ToolboxUpgraded

Event generated whenever Visual Studio upgrades its Toolbox.

Explicit Interface Implementations

IOleCommandTarget.Exec(Guid, UInt32, UInt32, IntPtr, IntPtr)

Executes a specified command or displays help for a command.

IOleCommandTarget.QueryStatus(Guid, UInt32, OLECMD[], IntPtr)

Queries the object for the status of one or more commands generated by user interface events.

IServiceContainer.AddService(Type, Object, Boolean)

Adds the given service to the VSPackage's service container.

IServiceContainer.AddService(Type, Object)

Adds the given service to the VSPackage's service container.

IServiceContainer.AddService(Type, ServiceCreatorCallback, Boolean)

Adds the given service to the service container by means of the specified ServiceCreatorCallback.

IServiceContainer.AddService(Type, ServiceCreatorCallback)

Adds the given service to the VSPackage's service container.

IServiceContainer.RemoveService(Type, Boolean)

Removes the given service type from the service container, and optionally promotes the removal of the service to parent service containers.

IServiceContainer.RemoveService(Type)

Removes the given service type from the service container.

IServiceProvider.GetService(Type)

Gets the service of the specified type.

IServiceProvider.QueryService(Guid, Guid, IntPtr)

Internal IServiceProvider implementation.

IVsAsyncUnifiedSettingsObserverFactory.CreateSettingsObserverAsync(Guid)

Instantiates Unified Settings observer identified by the given guid.

IVsPackage.Close()

Closes and disposes the package.

IVsPackage.GetAutomationObject(String, Object)

Gets an automation-friendly object for this package.

IVsPackage.GetPropertyPage(Guid, VSPROPSHEETPAGE[])

Proffers access to the Tools menu Options and the property pages of the Customize Toolbox dialog boxes.

IVsPackage.QueryClose(Int32)

Called to ask the VSPackage if the Visual Studio shell can be closed.

IVsPackage.ResetDefaults(UInt32)

Resets Toolbox defaults.

IVsPackage.SetSite(IServiceProvider)

Initializes the VSPackage in the Visual Studio environment.

IVsPersistSolutionOpts.LoadUserOptions(IVsSolutionPersistence, UInt32)

Loads user options for a given solution.

IVsPersistSolutionOpts.ReadUserOptions(IStream, String)

Reads user options for a given solution.

IVsPersistSolutionOpts.SaveUserOptions(IVsSolutionPersistence)

Saves user options for a given solution.

IVsPersistSolutionOpts.WriteUserOptions(IStream, String)

Writes user options for a given solution.

IVsToolboxItemProvider.GetItemContent(String, UInt16, IntPtr)

Gets an item.

IVsToolboxItemProvider2.GetItemContentAsync(String, UInt16)
IVsToolWindowFactory.CreateToolWindow(Guid, UInt32)

Creates a tool window of the specified type with the specified ID.

IVsUserSettings.ExportSettings(String, IVsSettingsWriter)

This method implements the IVsUserSettings Interface used to manage profiles and import/export settings to XML files.

IVsUserSettings.ImportSettings(String, IVsSettingsReader, UInt32, Int32)

Retrieves a VSPackage's configuration using the Visual Studio settings mechanism when a user selects the import option of the Import/Export Settings feature on the IDE’s Tools menu. This method is part of the implementation of the IVsUserSettings interface used to manage profiles and import/export settings to XML files.

IVsUserSettingsMigration.MigrateSettings(IVsSettingsReader, IVsSettingsWriter, String)

Migrates settings from a previous version.

IVsUserSettingsQuery.NeedExport(String, Int32)

Determines whether settings have changed and should be re-exported.

Extension Methods

QueryService(IServiceProvider, Guid)

Gets a service exposed by a service provider based on its service GUID.

QueryService<TService>(IServiceProvider)

Gets a service exposed by a service provider based on its service type.

Applies to