Shell Service Extensions |
Shell Services utility library for Visual Studio extension developers.
The Shell Services package provides extension methods to simplify access to services provided by service providers, as well as access to global services provided by the Visual Studio IDE.
Library Status: Public
This package may be installed through NuGet. Separate packages are available depending on the specific version of Visual Studio an extension is targeting.
Tvl.VisualStudio.ShellServices.10: For extensions targeting Visual Studio 2010 and newer.
Tvl.VisualStudio.ShellServices.11: For extensions targeting Visual Studio 2012 and newer.
Tvl.VisualStudio.ShellServices.12: For extensions targeting Visual Studio 2013 and newer.
This is a Utility Library package, as described on the Packages page. If you are registering this assembly using the ProvideCodeBaseAttribute attribute, use the following code to replace the described placeholders.
For extensions targeting Visual Studio 2012 and newer.
[assembly: ProvideCodeBase( AssemblyName = "Tvl.VisualStudio.ShellServices.11", Version = "1.0.0.0", CodeBase = "$PackageFolder$\\Tvl.VisualStudio.ShellServices.11.dll")]
For extensions targeting Visual Studio 2013 and newer.
[assembly: ProvideCodeBase( AssemblyName = "Tvl.VisualStudio.ShellServices.12", Version = "1.0.0.0", CodeBase = "$PackageFolder$\\Tvl.VisualStudio.ShellServices.12.dll")]
Extension methods for the following types are included.
Accessing MEF services from a package requires using the IComponentModel global service. For example, within an implementation of Initialize, the following code could be used to obtain an instance of the IVsEditorAdaptersFactoryService service, which is only provided as an MEF-exported component.
Package package = this; var componentModel = package.AsVsServiceProvider().GetComponentModel(); var exportProvider = componentModel.DefaultExportProvider; var service = exportProvider.GetExport<IVsEditorAdaptersFactoryService>();
Accessing global services from an MEF component is straightforward. Simply import an instance of SVsServiceProvider and use the appropriate extension methods to get an instance of the desired global service interface.
This package simplifies access to these global services by ensuring the correct access method is used. For example, consider the differences required for accessing each of the following services.
IVsAddProjectItemDlg: This global service is accessed by simply requesting an instance of SVsAddProjectItemDlg from the service provider. This naming pattern is common in the Visual Studio SDK, but not all-inclusive.
IServiceProvider: This global service is accessed by simply requesting an instance of the interface from the service provider.
IVsNavigationTool: This global service is accessed by requesting an instance of SVsClassView from the service provider. This interface is the best representation of the Class View pane, despite the fact that IVsClassView is another available interface.
IVsFontAndColorUtilities: This global service is accessed by requesting an instance of SVsFontAndColorStorage, and is one of two global service interfaces provided by this object (the other is IVsFontAndColorStorage).
IVsExpansionManager: This global service is accessed by first obtaining the IVsTextManager2 service, and calling the GetExpansionManager(IVsExpansionManager) method on the result.
IVsTextManager2: This global service is accessed by simply requesting an instance of VsTextManagerClass from the service provider. The pattern is similar to IVsAddProjectItemDlg above, but the naming convention is different.
IGlyphService: This global service is accessed by first obtaining an instance of IComponentModel from the service provider, and then calling the GetServiceT method. This pattern is common for global services that are provided through the Managed Extensibility Framework (MEF) rather than through the traditional Visual Studio service mechanisms.