Visual Commander extension lets you automate repetitive tasks in Visual Studio and change private IDE options.
You can quickly record a text editing macro and play it back multiple times:
You can reuse existing VB macros for Visual Studio 2008/2010 just pasting code in a Visual Commander command:
New commands can be written in C#:
A command can be executed from the dynamic VCmd menu, placed on a toolbar or assigned a keyboard shortcut.
The most basic task for a command is to modify selected text in the code editor:
// Block comment EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection; ts.Text = "/* " + ts.Text + " */";
// Insert GUID EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection; ts.Text = System.Guid.NewGuid().ToString();You can run existing Visual Studio commands from your code. They are easier to discover than APIs and easier to invoke:
// Close the current document tab and activate next if (IsCommandAvailable("Window.NextTab")) { EnvDTE.Window w = DTE.ActiveWindow; DTE.ExecuteCommand("Window.NextTab"); w.Close(); } else if (IsCommandAvailable("File.Close")) DTE.ExecuteCommand("File.Close");To analyze code and access code elements, you can use Visual Studio code model or Roslyn:
// Add an attribute to the current class and its properties EnvDTE.TextSelection ts = DTE.ActiveWindow.Selection as EnvDTE.TextSelection; EnvDTE.CodeClass codeClass = ts.ActivePoint.CodeElement[EnvDTE.vsCMElement.vsCMElementClass] as EnvDTE.CodeClass; codeClass.AddAttribute("DataContract", null); foreach (EnvDTE.CodeElement i in codeClass.Children) { if (i is EnvDTE.CodeProperty) (i as EnvDTE.CodeProperty).AddAttribute("DataMember", null); }
// Create a typed variable from the current method invocation. Microsoft.CodeAnalysis.Document document = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges(); Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax invocationExpressionNode = document.GetSyntaxRootAsync().Result.FindToken(caretPosition).Parent.AncestorsAndSelf(). OfType<Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax>().FirstOrDefault(); Microsoft.CodeAnalysis.SemanticModel semanticModel = document.GetSemanticModelAsync().Result; Microsoft.CodeAnalysis.IMethodSymbol methodSymbol = semanticModel.GetSymbolInfo(invocationExpressionNode).Symbol as Microsoft.CodeAnalysis.IMethodSymbol; textView.TextBuffer.Insert(invocationExpressionNode.SpanStart, methodSymbol.ReturnType.ToString() + " v = ");Visual Studio 2017+ now uses private registry settings making it harder to access. If you want to quickly set a registry setting to a specific value, one alternative is to run the following code from a Visual Commander command:
// Change find result format to remove the full path var key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\VisualStudio\" + DTE.Version + @"\Find"); key.SetValue("Find result format", @"$f$e($l): $t\r\n");
To perform some task automatically on a Visual Studio event (e.g. startup, build event, window or document operation, solution or project loading, debugger event), create a Visual Commander extension:
// Minimize Visual Studio on Debugging public void SetSite(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) { events = DTE.Events; debuggerEvents = events.DebuggerEvents; debuggerEvents.OnEnterRunMode += OnEnterRunMode; } private void OnEnterRunMode(EnvDTE.dbgEventReason reason) { if (reason == EnvDTE.dbgEventReason.dbgEventReasonGo) DTE.MainWindow.WindowState = EnvDTE.vsWindowState.vsWindowStateMinimize; }
Visual Studio UI is WPF based, so it is relatively easy to hide unwanted elements with Visual Commander. For example, it is possible to reclaim empty space below the main menu in Visual Studio 2019 when toolbars are not used:
There are many more command and extension examples on the site and some of them are included with the installer:
The free edition of Visual Commander is limited to 10 commands and 5 extensions. The professional edition (personal license costs $49) supports up to 99 commands and 50 extensions, plus adds IntelliSense and syntax highlighting for code editing, C# v6.0 - v8.0 to compile snippets, creation of common code modules, commands reordering for the VCmd menu and Visual Commander windows, navigation to relevant code from compiler errors, friendly command names for keyboard bindings, debugging of command execution.
Download the Visual Commander installer for Visual Studio 2019/2017/2015 and SSMS 17/2016 from the official site or Visual Studio Marketplace.
Copyright 2008 - 2023 Vlasov Studio (Best in class Visual Studio extensions and tools)