Click or drag to resize
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

Installation and Distribution

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.

    C#
    [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.

    C#
    [assembly: ProvideCodeBase(
        AssemblyName = "Tvl.VisualStudio.ShellServices.12",
        Version = "1.0.0.0",
        CodeBase = "$PackageFolder$\\Tvl.VisualStudio.ShellServices.12.dll")]
Using the Extension Methods

Extension methods for the following types are included.

Accessing MEF Services from a Package

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.

C#
Package package = this;
var componentModel = package.AsVsServiceProvider().GetComponentModel();
var exportProvider = componentModel.DefaultExportProvider;
var service = exportProvider.GetExport<IVsEditorAdaptersFactoryService>();

Accessing Global Services from an MEF Component

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.

Implementation Details

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.