API Overview

A side by side comparison of the equivalent APIs in Visual Studio Windows vs Visual Studio Mac

Overview

This article provides an overview of the common concepts in an IDE extension and what the equivalent API/object is in the other IDE.

Manifests

The manifest declares the information about our extension such as its name, author, copyright, identifier and version number.

Visual Studio Windows

A Visual Studio Windows extension has the VSIX manifest and the command manifest.

  • The VSIX manifest file (extension.vsixmanifest) defines the information about your extension such as name, author, version number and more. See here for documentation.
  • The Visual Studio Command Table (.vsct) defines the commands that your package contains. See here for documentation.

Visual Studio Mac

A Visual Studio Mac extension includes a file named Manifest.addin.xml that defines the extension points

To declare the name, author, copyright, version etc of an extension, we use the following attributes:

Package

The package is the central class that represents our extension and exposes it to the IDE.

Visual Studio Windows

We implement the AsyncPackage class to declare the core of our extension. See here for documentation.

Visual Studio Mac

Visual Studio Mac does not have the concept of a core package class.

Startup

For both Visual Studio Windows and Mac, extensions by default do not have a defined entry point. Extensions do not receive startup notifications by default and should be design so that they do not rely on a startup sequence.

Visual Studio Windows

To detect the startup of our extension in Visual Studio Windows, we register the loading of our package against a specified IDE event using the ProvideAutoLoad attribute attached to our Package.

See here for documentation.

Avoid relying on any form of startup event to initialise your Visual Studio Windows extension. The modern Visual Studio APIs (such as IntelliSense or adornments) and Roslyn APIs load feature implementations outside of

Visual Studio Mac

To detect the startup of our extension on Visual Studio Mac, we add a new CommandHandler to the /MonoDevelop/Ide/StartupHandlers extension point.

IDE Application

The IDE application is the root access point for most of the major APIs we would use in our extension.

Visual Studio Windows

In Visual Studio Windows the root IDE/application object is the DTE.

Importantly, the DTE also has the DTE2 interface that exposes many additional APIs.

Visual Studio Mac

In Visual Studio Mac, the root IDE/application object is the IdeApp.

Service Locator

The service locator is used to retrieve service implementations through a central access class.

Visual Studio Windows

In Visual Studio Windows, the service locator is the ServiceProvider class.

Below is an example of retrieving a service using the ServiceProvider:

var dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;

Visual Studio Mac

Visual Studio Mac does not have a service locator.

To access core services:

  • Use the static IdeServices to access core services like the ProjectService, TypeSystemService, DesktopService etc.
  • Use the CompositionManager to access parts that have been exported to MEF.
  • Use the IdeApp to access the core services such as the Workspace, Workbench

MEF Export Provider

The export provider is used to retrieve parts that are exported to the Managed Extensibility Framework.

Visual Studio Windows

We can access the export provider on Windows with the following code:

var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
var exportProvder = componentModel.DefaultExportProvider;

Visual Studio Mac

We can access the MEF composition manager on Mac with the following code:

MonoDevelop.Ide.Composition.CompositionManager.Instance.ExportProvider;

Commands

Visual Studio Windows

In Visual Studio Windows we declare command elements in a vsct file and register new commands using the OleMenuCommandService.

See here for documentation.

Visual Studio Mac

In Visual Studio Mac we create CommandHandler sub-classes and then connect that command instance into an extension point using the Manifest.addin.xml file.

See here for documentation.

Active Documents

The list of active, opened documents, also known as the running documents table, describe the documents that are currently open and have a source code editor user interface.

Visual Studio Windows

In Visual Studio Windows, we can the DTE2.Documents property to access the currently open documents.

To subscribe to document open/closed/modified events, we can use the DTE2.Events.DocumentEvents property.

Visual Studio Mac

In Visual Studio Mac, we can use the TypeSystemService.DocumentManager to query the currently opened documents and subscribe to open/closed/modified events.

Workspace Model

In IDE extensions we have the concept of a workspace model, that is, the hierarchical relationship of a solution, its projects and the files and references of those projects.

The workspace model is different to the compilation model as it incorporates project assets (like images or embedded resources), packages etc into the model. The workspace model is akin to what is displayed in the Solution Explorer, whereas the compilation model only contains information required to generate an executable.

Visual Studio Windows

Visual Studio Mac

Workspace Events

Pads

Pads are visual items that can be detached and moved around the IDE application.

Visual Studio Windows

In Visual Studio Windows, Pads are known as Tool Windows. To create one, we sub-class ToolWindowPane and add the [ProvideToolWindow(typeof(MyToolWindow))] attribute to our AsyncPackage to expose a new tool window.

Visual Studio Mac

In Visual Studio Mac, we implement the PadContent class and then present it using the IdeApp.Workbench.ShowPad method.

Solution Pad/Explorer

The solution explorer enables developers to visually explore the contents of the workspace model. It is presented as a tree-view in a detachable pad/tool window.

As extension developers, we may need to inspect the solution explorer to:

  • Understand what the currently selected item is (such as a project, file or solution).
  • Connect

Visual Studio Windows

In Visual Studio Windows we can access the solution explorer using the DTE.ToolWindows.SolutionExplorer API.

Visual Studio

In Visual Studio Mac we can access the solution explorer using the IdeApp.ProjectOperations API.