ReSharper Platform SDK
 
Because ReSharper Platform SDK undefined is still in development, this documentation may not be entirely accurate and is subject to change.

Component Model and Visual Studio interfaces

Last modified: 04 July 2023

The Component Model also allows access to any interface implemented by Visual Studio. However, it is recommended that you try and avoid the use of Visual Studio interfaces, as this usually ties your plugin to a particular version of Visual Studio, and requires the plugin to run in the Visual Studio hosted version of ReSharper. Your plugin won't run in the Command Line Tools version of ReSharper. You are strongly encouraged to use ReSharper interfaces and services whenever possible.

If you still need to get an interface implemented by Visual Studio, or by a Visual Studio extension, you can do this in several ways. The easiest is to simply inject the interface as a constructor parameter to your plugin component, or retrieve it from the Shell’s container. For example, to get to VS's Output Window interface IVsOutputWindow, you can acquire it with the following:

Note the use of Lazy<T>. Many of the Visual Studio interfaces can only be resolved using Lazy<T>, to allow for delay loading VS packages and assemblies, or Optional<T>, because there is no guarantee that interface is available - perhaps the required VS package isn't installed.

It is recommended that you use Lazy and Optional. If the plugin is run outside of the Visual Studio environment (e.g. in the Command Line Tools), the Visual Studio dependencies will not be available. It is better for your component to handle this gracefully than for the Component Model to be unable to create your component. An alternative is to mark your component as only being able to run in the Visual Studio environment, by passing in the ProgramConfigurations.VS_ADDIN flag to the component attribute. However, this can have a "viral" effect. If this component isn't created because you're not running inside Visual Studio, any other component that depends on this must also include the VS_ADDIN flag, or the Component Model will be unable to create it, also. A better solution is the use of Optional, Lazy, or perhaps moving the component into a Visual Studio specific assembly that is only loaded in the Visual Studio environment.

ReSharper only exposes a subset of Visual Studio's interfaces in this manner. In fact, the interfaces are only exposed to support ReSharper's own integration with Visual Studio. In addition, some interfaces are wrapped, to ensure correct usage, e.g. wrapping parameters for COM interop, releasing returned COM intptr's, checking returned HRESULTs, etc. You should consult the whitelist below to see what interfaces are available. If it's there, you can consume it via a component's constructor.

If you need to access interfaces that aren’t exposed, you have two options:

  1. Get access to the Microsoft.VisualStudio.OLE.Interop.IServiceProvider interface, and request it yourself

  2. Set up a class to expose the required interfaces from the container