title | description | date |
---|---|---|
Create your first extension reference |
A reference for creating your first OOP extension |
2022-11-22 |
This document is a quickstart that shows how to create your first extension using VisualStudio.Extensibility. The extension runs out-of-process, meaning outside of the Visual Studio process.
-
Visual Studio 2022 version 17.5 Preview 1 or higher with
.NET desktop development
workload. The latest minimum requirement will always be listed at Announcements page. -
Install latest version of VisualStudio.Extensibility Project System: This extension will allow you to debug extension projects using F5. There is currently no other deployment mechanism supported.
-
If you are updating from earlier builds, please make sure to update VisualStudio.Extensibility Project System to latest version as there are breaking changes in VisualStudio.Extensibility packages.
- Use
VisualStudio.Extensibility Project
template to create a new extensibility project.
At this point you are ready to start extending Visual Studio by adding commands and editor components to your extension.
The template creates Command1.cs
as your first command handler which you can use as a starting point. The default attributes shown below will place the command in Tools
menu with an extension icon.
[CommandIcon(KnownMonikers.Extension, IconSettings.IconAndText)]
[Command("Extension1.Command1", "Sample Remote Command", placement: CommandPlacement.ToolsMenu)]
When the command is executed, Visual Studio will call in to ExecuteCommandAsync
method where you can place a breakpoint. You can utilize context
argument or this.Extensibility
object to interact with Visual Studio.
For example, an example command handler could be as below:
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
{
await context.ShowPromptAsync(
"Hello from another process!",
PromptOptions.OK,
cancellationToken);
}
For more information on how to add commands, please refer to Commands section.
- Making sure that your extension project is selected as startup project in Visual Studio, press
F5
to start debugging. - This will build your extension and deploy it to the experimental instance of Visual Studio version you are using. The debugger should attach once your extension is loaded.
- You can find the command in
Tools
menu as shown.
Try a slightly more complex example, Create a simple extension.