Visual Commander v2.3 adds IntelliSense and syntax highlighting for command editing in VS 2015

Visual Commander is a freemium extension for Visual Studio 2010+ allowing you to automate repetitive tasks in the IDE.

Visual Commander Professional v2.3 adds IntelliSense and syntax highlighting for snippets editing in VS 2015:

See the full what’s new list.

Download the installer.

Posted in Vlasov Studio tools | Tagged , | Leave a comment

Microsoft C++ Core Guidelines Checker released

C++ Core Checker for Visual Studio is now available as a NuGet package.

The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++. Microsoft’s Guidelines Support Library (GSL) contains supporting functions and types.

Update (December 4): The Visual C++ Team published official description for C++ Core Guidelines Checkers usage.

Posted in Visual Studio news | Tagged , , , | 3 Comments

On changing Visual Studio 2015 icon

Visual Studio 2015 Update 1 have changed the main Visual Studio icon (which you see on the taskbar):

Visual Studio 2015 RTM icon

Visual Studio 2015 RTM icon

Visual Studio 2015 Update 1 icon

Visual Studio 2015 Update 1 icon

The intent was to make it different from the Visual Studio 2013 icon, but the result is not obviously better. In this article I will describe how you can set your own icon for Visual Studio.

If you have Visual Studio 2015 pinned to the taskbar, hide labels on taskbar buttons and just installed Update 1, you don’t see the new icon. The taskbar icon remains the RTM one.

For a new Visual Studio 2015 Update 1 installation or not pinned taskbar icon, the icon will be the new one. To change it, first unpin Visual Studio 2015 from taskbar if it is pinned. Then run VS 2015, right click on the VS taskbar icon, right click on the Visual Studio 2015 entry and select Properties:

Taskbar context menus

Taskbar context menus

In the Visual Studio 2015 Properties dialog, click Change Icon, Browse for example to the VS 2015 RTM icon and save changes:

When you restart Visual Studio, it will show your selected icon on the taskbar and you can pin it back if you want:

If your taskbar is configured to show labels, a running Visual Studio 2015 taskbar icon will always show the default Update 1 icon:

Labels on taskbar buttons

Labels on taskbar buttons

You can install the Set original Visual Studio 2015 RTM icon extension for Visual Commander to change the running VS icon with a label. By default, it downloads the RTM icon from my site, you can copy it locally to your %AppData% folder or substitute for any other icon:

Finally, it you like VS 2015 RTM icon, but want to differentiate it from VS 2013, you can install and customize Add version overlay to the Visual Studio 2015 taskbar icon extension for Visual Commander:

Version overlay for Visual Studio

Version overlay for Visual Studio

Go ahead and make Visual Studio 2015 looks the way you want it to look!

Update (January 26, 2016): Vishwanath Uppala published a VS 2015 icon in a different color.

Custom Visual Studio 2015 icon

Custom Visual Studio 2015 icon

Posted in Visual Studio tips | Tagged | Leave a comment

Hide code in the Visual Studio editor

You can easily hide any block of code in Visual Studio using the Hide Selection command. Invoke it from the main EditOutlining menu, Outlining context menu or with a shortcut to the Edit.HideSelection command:

Selected code will be collapsed under a plus sign (you can leave a part of the top line unselected to describe hidden content):

To remove this custom region, use the Stop Hiding Current command from the same menu.

Posted in Visual Studio tips | Leave a comment

Visual Studio customization with lightweight extensions and Visual Commander

Visual Studio is a very capable and mature IDE, plus there are 5,942 items in Visual Studio Gallery from 3rd parties, extending functionality even further in all possible directions. Still, if it is not written by you it can’t be perfect :)

The hardest part when writing a Visual Studio extension is to find the right interface for the task. In this article I will show most “popular” interfaces to help you get started with Visual Studio customization using code. When there is no public API to perform your task, I’ll show possible workarounds.

All samples below are available as commands and extensions for Visual Commander. You can use this code as part of your own extension or you can run it directly with Visual Commander. Generally, for relatively simple functionality Visual Commander helps you write, run, customize and share VS extension code faster than with a full VSIX package. Most of the code will also run unmodified for all Visual Studio versions from VS 2010 to VS 2015 (when creating a full VSIX package you should carefully package it to provide compatibility with different versions of Visual Studio). Visual Commander also provides the common VCmd menu to run and organize multiple commands and extensions.

The most basic task for an extension is to modify selected text in the code editor. Block comment and Insert date and time commands demonstrate access to the current selection as string:

EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
ts.Text = "/* " + ts.Text + " */";

You can run existing Visual Studio commands from your code. They are easier to discover than APIs and easier to invoke. See for example 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");

Another very common requirement is to perform some task automatically on a Visual Studio event. See the list of Common Visual Studio environment events and see Open a file from the solution directory on opening a solution, Run Cppcheck on the saved file samples:

public void SetSite(EnvDTE80.DTE2 DTE_, Microsoft.VisualStudio.Shell.Package package)
{
	events = DTE.Events;
	documentEvents = events.DocumentEvents;
	documentEvents.DocumentSaved += OnDocumentSaved;
}

private void OnDocumentSaved(EnvDTE.Document doc)
{
	if(doc.Language == "C/C++")
		RunCppcheck(doc.FullName);
}

You can create custom commands to programmatically setup different Visual Studio options. For example, Toggle line numbers for C# files and Set font size:

dim v = DTE.Properties("TextEditor", "CSharp").Item("ShowLineNumbers").Value
DTE.Properties("TextEditor", "CSharp").Item("ShowLineNumbers").Value = Not v

To analyze code, you can use Visual Studio code model, for example Move the caret to the beginning of the containing function, Copy to the clipboard properties of the selected class in Visual Studio text editor and Copy current file, line, method. Alternatively, you can use Roslyn, for example Create a typed variable from the current method invocation:

Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax invocationExpressionNode = 
	document.GetSyntaxRootAsync().Result.FindToken(caretPosition).Parent.AncestorsAndSelf().
	OfType<Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax>().FirstOrDefault();
if (invocationExpressionNode != null)
{
	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 is a .NET, Windows, WPF application and your code runs as a part of it. If there is no public API for your needs, you can directly enumerate and modify WPF UI controls (Hide Sign in and Feedback smiley buttons in Visual Studio 2013/2015), subscribe to Application events (AutoSave files when Visual Studio loses focus), modify the MainWindow (Add version overlay to the Visual Studio 2015 taskbar icon) and simulate keyboard input with SendKeys (Toggle CodeLens on/off). As a last resort you can use .NET reflection to access internal Visual Studio assemblies.

I hope you are now feeling empowered to spend some time and add a feature to Visual Studio that you always wanted. Don’t hesitate to share your code and ask questions in comments.

Posted in Visual Studio tips, Vlasov Studio tools | Tagged | 2 Comments

Sync Block Edit v1.2 adds support for Visual Studio 2015

Sync Block Edit is a free extension that lets you easily update duplicate blocks of text in multiple files from Visual Studio 2010+.

v1.2 adds support for Visual Studio 2015.

Download the installer.

Posted in Vlasov Studio tools | Tagged , | Leave a comment

Code reference hyperlinks in Visual Studio 2015

Visual Studio 2015 allows you to create links to classes and method in other files from a comment in your C# code:

When the cursor is inside the cref attribute, pressing F12 or selecting Go To Definition opens the corresponding file with the referenced method.

When typing the referenced class or method, IntelliSense autocomplete is available. You can specify an external namespace for the target if needed. The Go To Definition command works with any tag name (e.g. <a>), but for proper XML documentation it is recommended to use <see> or <seealso>.

(This feature was first described by Peter Macej here).

Posted in Visual Studio tips | Tagged | Leave a comment