Visual Studio Extensions Tutorials
Learn how to build powerful extensions for Visual Studio to customize your development experience.
Getting Started with Visual Studio Extension Development
An introductory guide to setting up your environment and creating your first simple Visual Studio extension.
Start NowCreating Custom Tool Windows
Discover how to add your own interactive tool windows to the Visual Studio IDE.
Learn MoreImplementing Editor Enhancements
Enhance the code editor with features like syntax highlighting, code completion, and refactorings.
ExploreWorking with the VSSDK API
A deep dive into the Visual Studio SDK, covering key classes and patterns for advanced extension development.
Read DetailsPackaging and Deploying Extensions
Learn how to package your extensions for distribution and installation.
GuideAdvanced Topics: Commands and Menu Items
Add custom commands and integrate them into Visual Studio's menus and toolbars.
DiscoverExample: Adding a Simple Command
using Microsoft.VisualStudio.Shell;
using System;
using System.ComponentModel.Design;
using System.Globalization;
using System.Threading.Tasks;
using Task = System.Threading.Tasks.Task;
namespace MyAwesomeExtension
{
internal sealed class MyCommand : AsyncPackage
{
public const int CommandId = 0x0100;
public static readonly Guid CommandSet = new Guid("b11e020e-937b-400a-995b-e8f0b189f13f");
public MyCommand()
{
// Initialize the package
}
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await base.InitializeAsync(cancellationToken, progress);
await JoinableTaskFactory.SwitchToMainThreadAsync();
var commandService = await GetServiceAsync(typeof(IMenuCommandService)) as IMenuCommandService;
var menuCommandID = new CommandID(CommandSet, CommandId);
var menuItem = new OleMenuCommand((s, e) => this.Execute(), menuCommandID);
commandService.AddCommand(menuItem);
}
private void Execute()
{
VsShellUtilities.ShowMessageBox(this,
"Hello World from My Awesome Extension!",
"My Command",
OLEMSGICON.OLEMSGICON_INFO,
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
OLEMSGRESULT.OLEMSGRESULT_OK);
}
}
}