بنقرة واحدة
macro-toolkit-api
Use the Community.VisualStudio.Toolkit facade from inside Macros .csx files
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Use the Community.VisualStudio.Toolkit facade from inside Macros .csx files
التثبيت باستخدام 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
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-toolkit-api |
| description | Use the Community.VisualStudio.Toolkit facade from inside Macros .csx files |
| domain | visual-studio-macros |
| confidence | high |
| source | derived from repo usage of VS.StatusBar, VS.MessageBox, VS.InfoBar, and VS.Documents |
Use the VS facade inside a macro for friendly shell UI, document services, and lightweight Visual Studio interactions.
Use this skill when the macro should show status, warn the user, display an info bar, or query the active document view through Community.VisualStudio.Toolkit.
Do not use this skill for writing Toolkit-based VSIX commands, tool windows, or package services. In this repo, the toolkit is consumed from inside .csx macros only.
VS facadeInside a macro, VS refers to the static Community.VisualStudio.Toolkit facade.
Reference: https://github.com/VsixCommunity/Community.VisualStudio.Toolkit/wiki
Typical calls look like this:
await VS.StatusBar.ShowMessageAsync("Macro started");
await VS.MessageBox.ShowWarningAsync("Macros", "Nothing is selected");
Use the status bar for lightweight diagnostics and progress breadcrumbs:
await VS.StatusBar.ShowMessageAsync("Formatting current document...");
await ExecuteCommandAsync("Edit.FormatDocument");
await VS.StatusBar.ShowMessageAsync("Format complete");
Choose the status bar when the message is informative and non-blocking.
Use a message box when the user must notice the problem:
if (DTE.ActiveDocument == null)
{
await VS.MessageBox.ShowWarningAsync("Macros", "Open a document first.");
return;
}
Good uses:
Info bars work well for richer, dismissible notifications.
var model = new InfoBarModel(
textSpans: new[]
{
new InfoBarTextSpan("Macro finished. Review the Output window if you need details.")
},
actionItems: new[]
{
new InfoBarHyperlink("Open Output", "open-output")
},
image: Microsoft.VisualStudio.Imaging.KnownMonikers.StatusInformation,
isCloseButtonVisible: true);
InfoBar? bar = await VS.InfoBar.CreateAsync(model);
if (bar != null)
{
await bar.TryShowInfoBarUIAsync();
}
Use an info bar when a status-bar message is too easy to miss but a modal dialog would be too heavy.
Use the document service when the macro needs the active editor surface, not just DTE.ActiveDocument metadata:
DocumentView? view = await VS.Documents.GetActiveDocumentViewAsync();
if (view?.TextView == null)
{
await VS.StatusBar.ShowMessageAsync("No active text view");
return;
}
await VS.StatusBar.ShowMessageAsync($"Text view ready for {view.FilePath}");
A common macro pattern is:
DTE or VS.DocumentsExecuteCommandAsync or TypeAsyncVS.StatusBar, VS.MessageBox, or VS.InfoBarExample:
DocumentView? view = await VS.Documents.GetActiveDocumentViewAsync();
if (view == null)
{
await VS.MessageBox.ShowWarningAsync("Macros", "No active document view.");
return;
}
await ExecuteCommandAsync("Edit.FormatDocument");
await VS.StatusBar.ShowMessageAsync($"Formatted {view.FilePath}");
await VS.StatusBar.ShowMessageAsync("Macros: Done");
await VS.MessageBox.ShowWarningAsync("Macros", "This macro needs an open text document.");
InfoBar? bar = await VS.InfoBar.CreateAsync(
new InfoBarModel(
textSpans: new[] { new InfoBarTextSpan("Build failed — open Error List?") },
actionItems: new[] { new InfoBarHyperlink("Open", "open-errors") },
image: Microsoft.VisualStudio.Imaging.KnownMonikers.StatusWarning,
isCloseButtonVisible: true));
if (bar != null)
{
await bar.TryShowInfoBarUIAsync();
}
When generating Toolkit-based macros:
VS.StatusBar.ShowMessageAsync for quick feedbackVS.MessageBox.ShowWarningAsync for important warningsVS.InfoBar.CreateAsync when the user needs a clickable, non-modal notificationawait VS.Documents.GetActiveDocumentViewAsync() when the macro needs the live document view