/vs-extensibility-skills:controlling-visual-studiofrom vs-extensibility-skills
Controls a running Visual Studio IDE via COM automation from the terminal. Opens files at specific lines, executes IDE commands (build, format, debug), and manages projects/documents.
Ships in vs-extensibility-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Control a running Visual Studio instance from a PowerShell terminal by
acquiring its EnvDTE.DTE COM automation object out of the Windows Running
Object Table (ROT).
Scope: Windows-local only. Does not work over SSH, WSL, dev containers, or Codespaces — the ROT is per-Windows-session.
controlling-visual-studio/
├── SKILL.md ← this file
├── scripts/
│ ├── RotHelper.dll ← prebuilt P/Invoke + ROT helper (~4 KB)
│ └── Connect-VsDte.ps1 ← bootstrap + high-level verbs
└── src/
├── RotHelper.cs ← source for the DLL (auditable)
└── build.ps1 ← rebuild scripts/RotHelper.dll
Dot-source Connect-VsDte.ps1 once per pwsh session, then call the verbs.
Substitute the absolute path to the skill folder; the script knows its own
location ($PSScriptRoot) and finds RotHelper.dll next to it.
. '<skill-dir>/scripts/Connect-VsDte.ps1'
# Open a file at a specific line
Open-VsFile -Path C:\repo\src\Foo.cs -Line 42
# Execute any registered DTE command
Invoke-VsCommand 'File.SaveAll'
Invoke-VsCommand 'View.ErrorList'
Invoke-VsCommand 'Edit.FormatDocument'
# Build, with timeout
Invoke-VsBuild -TimeoutSeconds 600 # async + poll
Invoke-VsBuild -WaitForBuildToFinish # synchronous
# Direct DTE access for anything not wrapped
$dte = Get-VsDte
$dte.Debugger.CurrentMode # 1=Design, 2=Break, 3=Run
$dte.ActiveDocument.FullName
Get-VsDte picks the right Visual Studio instance using this priority:
ProcessHelper.FindAncestorByName($PID,'devenv')).
Deterministic when pwsh was launched from VS's integrated terminal.
Uses NtQueryInformationProcess — completes in milliseconds.-SolutionMatch '*MySolution*') when not running
under devenv.The selected DTE is cached in a script-scoped variable; subsequent calls in the same session reuse it (with a liveness check).
Connect-VsDte.ps1| Function | Purpose |
|---|---|
Get-VsDte | Acquire (or reuse cached) DTE for the host VS instance. |
Open-VsFile | Open a file, optionally jumping to Line/Column. |
Invoke-VsCommand | Call DTE.ExecuteCommand(name, args). |
Invoke-VsBuild | Build the solution; sync or async-with-timeout. |
Invoke-WithComRetry | Wrap any DTE call to retry RPC_E_CALL_REJECTED / RETRYLATER. |
Discover command names via (Get-VsDte).Commands | ? Name | Select Name.
. '<skill-dir>/scripts/Connect-VsDte.ps1'
$repoRoot = (& git rev-parse --show-toplevel).Trim()
git -C $repoRoot status --porcelain=v1 | ForEach-Object {
$path = $_.Substring(3).Trim().Trim('"')
if ($path -match ' -> ') { $path = $path -replace '^.* -> ','' }
$full = Join-Path $repoRoot $path
if (Test-Path -LiteralPath $full -PathType Leaf) { Open-VsFile -Path $full }
}
Per-invocation wall time on a modern dev box (cold pwsh, warm DLL):
| Phase | Time |
|---|---|
pwsh.exe startup | ~300–400 ms |
Add-Type -Path (load DLL) | ~60–110 ms |
| Parent-process walk | ~5 ms |
| ROT enumeration | ~25 ms |
| First DTE call | ~30 ms |
| Total | ~450–550 ms |
For lower latency (~5–10 ms per call) consider an in-VS named-pipe server shipped as a VSIX. Out of scope for this skill.
If you change src/RotHelper.cs:
pwsh -NoProfile -File '<skill-dir>/src/build.ps1'
This regenerates scripts/RotHelper.dll.
$dte.Solution,
$dte.Debugger.CurrentMode, $dte.ActiveDocument first.ExecuteCommand calls
raise UI prompts (e.g. closing dirty documents); never script SendKeys to
dismiss them.Tools.Options). Avoid invoking
modal commands from automation unless the user explicitly asks.| Symptom | Cause | Fix |
|---|---|---|
RotHelper.dll not found | Skill checked in without binary, or moved | Run src/build.ps1 to regenerate. |
ROT empty but devenv.exe is running | Integrity-level mismatch | Match elevation between VS and pwsh. |
RPC_E_CALL_REJECTED / RETRYLATER | VS busy | Wrap in Invoke-WithComRetry. |
| Wrong instance picked | Multiple devenvs, terminal not a child of VS | Pass -SolutionMatch '*Name*' to Get-VsDte. |
MoveToLineAndOffset throws | Active item is not a text document (e.g. designer) | Open-VsFile already best-efforts this; check Document.Type. |
Hangs in Invoke-VsBuild | Long build, or VS prompting | Increase -TimeoutSeconds; check VS UI for modal dialogs. |
| Works in Windows PowerShell, fails in pwsh 7 | MTA apartment | Launch with pwsh -STA for sessions making many DTE calls. |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Generated from the plugin's indexed repository (madskristensen/vs-agent-plugins) — no native marketplace selected
npx claudepluginhub p/madskristensen-vs-extensibility-skills41 skills in this plugin
/adding-codelens-indicatorsAdd custom CodeLens indicators that display inline information above code elements in the Visual Studio editor. Use when the user asks how to add a CodeLens indicator, show inline data above methods or classes, create a custom CodeLens provider, implement IAsyncCodeLensDataPointProvider, display git history or test status in CodeLens, or add a details popup to CodeLens entries. Covers VSSDK / VSIX Community Toolkit (in-process + out-of-process CodeLens service). VisualStudio.Extensibility (out-of-process) does not have a dedicated CodeLens API./adding-commandsAdd commands (menu items, toolbar buttons) to Visual Studio extensions. Use when the user asks how to create a command, add a menu item, add a toolbar button, register a command handler, wire up a .vsct file, use KnownMonikers icons on buttons, or place commands in menus/toolbars in a Visual Studio IDE extension. Covers VisualStudio.Extensibility (out-of-process), VSIX Community Toolkit (in-process), and legacy VSSDK (in-process) approaches./adding-context-menusAdd native-looking context menus to custom WPF UI in Visual Studio extensions (tool windows, custom tree views, list views). Use when the user wants to show a right-click context menu from their own UI that looks native to VS. Covers defining VSCT context menus (type="Context"), grouping commands with separators, and programmatically showing them via IVsUIShell.ShowContextMenu. Do NOT use regular WPF ContextMenu — it won't match VS theming or support command routing. Covers VSSDK and VSIX Community Toolkit (in-process). VisualStudio.Extensibility (out-of-process) does not support VSCT-based context menus on custom UI.Other plugins' skills for the same job