Getting Started
This tutorial walks you through the end‑to‑end process of building a Visual Studio extension (VSIX). We'll cover:
- Prerequisites and environment setup
- Creating a new VSIX project
- Understanding the extension manifest
- Adding a command and UI elements
- Testing and debugging the extension
- Packaging and publishing to the Marketplace
Prerequisites
Make sure you have the following installed:
• Visual Studio 2022 (Community, Professional, or Enterprise)
• .NET 6.0 SDK (or later)
• Optional: Git for source control
Sample Extension: “Hello World” Command
C#
.vsixmanifest
using System;
using System.ComponentModel.Design;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;
namespace HelloWorldExtension
{
internal sealed class HelloWorldCommand
{
public const int CommandId = 0x0100;
public static readonly Guid CommandSet = new Guid("d3f8c45a-7b3e-4b2a-9c6e-1a2b345cdef0");
private readonly AsyncPackage package;
private HelloWorldCommand(AsyncPackage package, OleMenuCommandService commandService)
{
this.package = package ?? throw new ArgumentNullException(nameof(package));
var cmdID = new CommandID(CommandSet, CommandId);
var menuItem = new MenuCommand(Execute, cmdID);
commandService.AddCommand(menuItem);
}
public static async Task InitializeAsync(AsyncPackage package)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
var commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
new HelloWorldCommand(package, commandService);
}
private void Execute(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
VsShellUtilities.ShowMessageBox(
this.package,
"Hello, World! Your extension is working.",
"Hello World",
OLEMSGICON.INFO,
OLEMSGBUTTON.OK,
OLEMSGDEFBUTTON.DEFAULT);
}
}
}
<PackageManifest Version="2.0.0">
<Metadata>
<Identity Id="HelloWorldExtension" Version="1.0.0" Language="en-US" Publisher="YourName" />
<DisplayName>Hello World Extension</DisplayName>
<Description xml:space="preserve">A simple command that shows a message box.</Description>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0,18.0)" />
</Installation>
<Assets>
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="File" Path="HelloWorldExtension.dll" />
<Asset Type="Microsoft.VisualStudio.Commands" d:Source="File" Path="HelloWorldExtension.pkgdef" />
</Assets>
</PackageManifest>
Debugging Your Extension
Press F5 to launch an experimental instance of Visual Studio. The extension will be loaded automatically. Use the Output window (Show → Output) to view diagnostic messages.
Packaging & Publishing
Run dotnet pack or right‑click the project → Publish to generate a .vsix file. Upload it to the Visual Studio Marketplace following the submission guidelines.