ワンクリックで
macro-debugging
Troubleshoot Macros .csx scripts: command names, null state, timing, and runtime vs IntelliSense
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Troubleshoot Macros .csx scripts: command names, null state, timing, and runtime vs IntelliSense
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
{what this skill teaches agents}
Use EnvDTE80.DTE2 inside Macros .csx files to inspect and automate Visual Studio
Use the Community.VisualStudio.Toolkit facade from inside Macros .csx files
Trigger syntax for Macros .csx files: events, commands, filters, and header edits
How to write .csx macros for Visual Studio automation in the Macros repo
{what this skill teaches agents}
| name | macro-debugging |
| description | Troubleshoot Macros .csx scripts: command names, null state, timing, and runtime vs IntelliSense |
| domain | visual-studio-macros |
| confidence | high |
| source | derived from player/shim behavior, helper contracts, and repo docs |
Troubleshoot failing or flaky .csx macros by checking command names, IDE state, async usage, and the editor-only IntelliSense shim.
Use this skill when a macro compiles but fails at runtime, when IntelliSense looks right but playback behaves differently, or when a recorded macro needs timing and guard checks.
Do not use this skill for attaching a debugger to a VSIX package or diagnosing extension load problems.
If this line fails:
await ExecuteCommandAsync("Edit.SomeCommand");
The usual cause is a wrong command name.
Use command names exactly as Visual Studio knows them, such as Edit.FormatDocument, File.Save, or Build.BuildSolution.
await VS.StatusBar.ShowMessageAsync("Running Edit.FormatDocument");
await ExecuteCommandAsync("Edit.FormatDocument");
DTE.ActiveDocument is nullA macro that assumes an open editor can fail when no document is active.
if (DTE.ActiveDocument == null)
{
await VS.StatusBar.ShowMessageAsync("No active document");
return;
}
Do the same for selections:
var sel = DTE.ActiveDocument?.Selection as EnvDTE.TextSelection;
if (sel == null)
{
await VS.StatusBar.ShowMessageAsync("No active text selection");
return;
}
The .intellisense/Macros.Intellisense.csx file is an editor aid, not runtime logic.
Important facts:
#r, common imports, and stub globals so the editor understands the fileIf the editor knows DTE, VS, Context, and Trigger, but playback still fails, check the live IDE state rather than the #load line.
#load directive at runtimeKeep this in the file:
#load ".intellisense/Macros.Intellisense.csx"
At runtime, the player intercepts that path and returns empty source. That is expected.
Do not debug by deleting the line.
Some VS actions need a short delay before the next step.
await ExecuteCommandAsync("File.SaveSelectedItems");
await WaitAsync(250);
await ExecuteCommandAsync("Edit.FormatDocument");
Use small waits first. Prefer checking state when you can; use delays only when sequencing is the real issue.
Macros are more reliable when they verify prerequisites first.
if (DTE.ActiveDocument?.Name.EndsWith(".cs", StringComparison.OrdinalIgnoreCase) != true)
{
await VS.StatusBar.ShowMessageAsync("This macro expects an open C# document");
return;
}
await ExecuteCommandAsync("Edit.FormatDocument");
For quick diagnostics, emit breadcrumbs with the status bar:
await VS.StatusBar.ShowMessageAsync("Step 1: locating selection");
var sel = DTE.ActiveDocument?.Selection as EnvDTE.TextSelection;
await VS.StatusBar.ShowMessageAsync($"Step 2: selection found = {sel != null}");
All built-in helpers are async. Correct:
await TypeAsync("Hello");
await OpenFileAsync(@"C:\Repos\MySolution\Program.cs");
Incorrect:
TypeAsync("Hello");
OpenFileAsync(@"C:\Repos\MySolution\Program.cs");
If you skip await, the macro may race ahead or finish before the operation completes.
Macros are scripts. You normally do not need classes, package setup, or extension scaffolding.
if (DTE.ActiveDocument != null)
{
await ExecuteCommandAsync("Edit.FormatDocument");
}
await?WaitAsync(...) between steps?VS.StatusBar.ShowMessageAsync(...) breadcrumb pinpoint the failure?DTE.ActiveDocument or SelectionWaitAsync only for real timing issues