Resource Page DescriptionThis sample shows how to be a Visual Studio service provider and how to consume Visual Studio services.
Introduction:
There are three samples associated with this project, one for each programming language.
C++ The sample contains three main classes. A service provider package called ServiceProviderPackage,
a service consumer package called ServiceConsumerPackage, and a local service provider called
LocalServiceProvider, which belongs to the service provider package.
ServiceProviderPackage registers its service in the Visual Studio registry so that it will be
loaded when any package queries for the service. In this sample ServiceConsumerPackage will
do this. Additionally, ServiceProviderPackage offers this service to Visual Studio when it is
loaded. Simply registering the service in the Visual Studio registry is insufficient to allow a
client to successfully query for it.
ServiceConsumerPackage registers its menu and provides three menu items on the Visual Studio Tools
menu entitled:
- "VSSDK C++ Execute Global Service"
- "VSSDK C++ Execute Local Service"
- "VSSDK C++ Execute Local using Global Service"
The command handlers for these menu items are provided by ServiceConsumerPackage. Each handler
attempts to query for either the globally offered service provided by ServiceProviderPackage
or the local service provided by ServiceProviderPackage. Querying for the local service is
expected to fail. Utilizing each menu item will cause a text string to be sent to the Output
window. (NOTE - There is a bug in the Output window. If you don't see the text, then simply restart Visual Studio).
C# and VB This sample shows how to create and expose services inside Visual Studio. It creates two services with two
different levels of visibility. The service with global visibility is available for any of Visual Studio's other components. The service with
local visibility is available only from within the package itself or when the IServiceProvider interface
implemented by the package is inside the chain of active providers.
The sample creates two assemblies, one with the definition of the interfaces used and one with the actual
implementation of the packages and services. The assembly with the implementation, created by the Reference.Services
project, defines two packages. One package exposes the services and a second package uses them. The services are
implemented with two helper classes.
The part of interest about how to proffer services is the code inside the ServicesPackage class. Specifically:
1. In the declaration of the class we use the ProvideServiceAttribute registration attribute defined in the
Managed Package Framework to add the information about the global service proffered
by the package to the registry.
2. In the constructor of the package we add the types of the proffered services to the list of the services
provided by the package. Notice that at this point we don’t create any instance of the service, but we
provide a callback function that will be called the first time a client queries for a specific service.
We do this to optimize performance. We don’t want to construct something that might never
be used.
3. The callback function used to create a new instance of the services.
Requirements:
- Visual Studio 2010 Beta 2
- Visual Studio 2010 SDK Beta 3
Download and install:
- Download the zip file associated with the sample
- Unzip the sample to your machine
- Double click on the .sln file to launch the solution
Building and running the sample
- To build and execute the sample, press F5 after the sample is loaded
- Add any other special information here.