ワンクリックで
macro-triggers
Trigger syntax for Macros .csx files: events, commands, filters, and header edits
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Trigger syntax for Macros .csx files: events, commands, filters, and header edits
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
{what this skill teaches agents}
Troubleshoot Macros .csx scripts: command names, null state, timing, and runtime vs IntelliSense
Use EnvDTE80.DTE2 inside Macros .csx files to inspect and automate Visual Studio
Use the Community.VisualStudio.Toolkit facade from inside Macros .csx files
How to write .csx macros for Visual Studio automation in the Macros repo
{what this skill teaches agents}
| name | macro-triggers |
| description | Trigger syntax for Macros .csx files: events, commands, filters, and header edits |
| domain | visual-studio-macros |
| confidence | high |
| source | derived from docs/triggers.md and CSharpCodeGenerator.EmitHeader |
Add // @trigger lines to the top comment block so a macro runs automatically on IDE events or commands.
Use this skill when the user wants a macro to run on save, build, solution open, debugger events, or before/after a named Visual Studio command.
Do not use this skill for VSIX event handlers, MEF listeners, command filters, or other extensibility plumbing.
A trigger is always a top-of-file comment line:
// @trigger Manual
// @trigger Build.SolutionBuildDone
// @trigger Build.SolutionBuildDone when success=false
// @trigger Document.Saved when filename=*.cs
// @trigger BeforeCommand File.Save
// @trigger AfterCommand Build.BuildSolution
Rules:
Event triggers use {Category}.{EventName}:
// @trigger Build.SolutionBuildDone
// @trigger Document.Saved
// @trigger Document.Opened
// @trigger Solution.OnAfterOpenSolution
// @trigger Debugger.EnterBreakMode
Common categories in this repo include Build, Document, Solution, Debugger, Selection, Window, and Shell.
Practical example:
// @trigger Document.Saved when filename=*.cs
#load ".intellisense/Macros.Intellisense.csx"
await ExecuteCommandAsync("Edit.FormatDocument");
await VS.StatusBar.ShowMessageAsync("Formatted after save");
Command triggers attach to named VS commands:
// @trigger BeforeCommand File.Save
// @trigger AfterCommand Build.BuildSolution
Use BeforeCommand to intervene before execution and AfterCommand to react after execution.
// @trigger BeforeCommand File.Save
#load ".intellisense/Macros.Intellisense.csx"
if (DTE.Solution.SolutionBuild.BuildState == EnvDTE.vsBuildState.vsBuildStateInProgress)
{
await VS.MessageBox.ShowWarningAsync("Macros", "Cannot save during a build.");
Trigger.CancelCommand();
}
when filtersAdd when key=value after the trigger name to narrow when it fires.
Common filters:
filename=*.cssuccess=falseproject=*Tests*exception=*NullReferenceException*// @trigger Document.Saved when filename=*.cs
// @trigger Build.SolutionBuildDone when success=false
// @trigger Build.ProjectBuildDone when project=*Tests* success=true
// @trigger Debugger.ExceptionThrown when exception=*ArgumentException*
Filter rules:
key=value pairs are AND-combinedfilename is a glob, not a regexsuccess is a booleanExisting file:
// Macro: Format on Save
// Recorded: 2026-05-02T17:10:39Z
// Steps: 1
// Generated by Macros — edit freely.
#load ".intellisense/Macros.Intellisense.csx"
await ExecuteCommandAsync("Edit.FormatDocument");
Add a trigger line inside the header block:
// Macro: Format on Save
// Recorded: 2026-05-02T17:10:39Z
// Steps: 1
// Generated by Macros — edit freely.
// @trigger Document.Saved when filename=*.cs
#load ".intellisense/Macros.Intellisense.csx"
await ExecuteCommandAsync("Edit.FormatDocument");
Do not move the trigger below #load or below executable statements.
Generated macros include examples like these:
// EXAMPLE: // @trigger Build.SolutionBuildDone
// EXAMPLE: // @trigger Document.Saved when filename=*.cs
// EXAMPLE: // @trigger BeforeCommand File.Save
// EXAMPLE: // @trigger AfterCommand Build.BuildSolution
To activate one, remove only the // EXAMPLE: prefix.
// @trigger Build.SolutionBuildDone when success=false
// @trigger Document.Opened when filename=*.xaml
// @trigger AfterCommand Edit.FormatDocument
// @trigger ... in the header blockDocument.Saved or Document.Opened for document automationBeforeCommand only when cancellation/interception mattersAfterCommand for logging or follow-up workwhen filters instead of branching later when the condition is simple