Did you know… There’s is a Go To Definition navigation stack?! – #367

update 2 dec 2008: This feature originated in C++ over 10 years ago. My bad C++ folks for my earlier statements that it was only a C# feature.

I added the exclamation point, because I never knew this. It is amazing that I’m still finding out about IDE features! When does the madness end? But in all fairness, this is a specific C# IDE feature, as it relates to the Go To Definition Window. (Sorry VB folks to do this to you yet again.)

We know that Visual Studio has a navigation stack because of the Navigate Forward and Navigate Backward keyboard shortcuts. But apparently, and little did I know, that Visual Studio has a separate navigation stack to track cursor movement for Go To Definition calls (but only for C# code?)

Start off by doing a Go To Definition, and of course the cursor moves to the definition. Now to get back to where you were before, you can use CTRL+SHIFT+8.

View.PopBrowseContext command

And to return to the definition, press CTRL+SHIFT+7.

View.ForwardBrowseContext Ctrl+Shift+7

I’ll be honest here and share that it has taken me over 30 minutes to figure out how this navigation stack works. It wasn’t until I took the screenshot for the Ctrl+Shift+8 keyboard shortcut and realized the command name was “View.PopBrowseContext” that I began to understand what is going on.

Ctrl+Shift+7 will push definitions onto the stack and Ctrl+Shift+8 will pop them off. What was hard for me to get is that this navigation stack is really a “stack,” meaning that push=Go To Definition and pop=go to location the Go To Definition was called. In other words, if you do as many Ctrl+Shift+7 as possible until you run out of definitions (implying an empty stack) and then do a Ctrl+Shift+8 to do a Go To Definition, the stack will have only one definition on it. So your next Ctrl+Shift+7 will only have one place to visit.

Please correct me if I’m wrong but I think this is just a VS2008 feature.

Technorati Tags: VS2008Tip

Did you know… There’s a way to have Visual Studio log its activity for troubleshooting? – #366

There’s a built-in command line switch devenv.exe /log to log Visual Studio activity, e.g. which packages got loaded, etc. I’ll call out immediately that the documentation is wrong, but you should read Paul’s comments at the bottom of the page for the real documentation (Paul was a dev on VS). http://msdn.microsoft.com/en-us/library/ms241272.aspx

command line devenv /log

If no file is specified, the log is written to

%APPDATA%\Microsoft\VisualStudio\9.0\ActivityLog.xml

And yes, since it is Happy Turkey Day once again, here’s my picture from last time, tip #089 to be exact.

Happy Turkey Day!

Technorati Tags: VS2005Tip,VS2008Tip

Did you know… How to add a Linked Item to a project – #365

This feature is helpful when you need a common file shared among projects, like a bitmap, readme, set of common tools and utilities, etc.

To add, right-click on the project in the solution explorer, and select Add – Existing Item.  You’ll notice the “Add” button is one of those button-dropdowns.  Drop down the Add button and select Add a link

Add Existing Item with Add as Link selected

Now you have a linked item in your project as indicated by the shortcut icon.

Linked item in Solution Explorer

The location of the linked file is saved in the project file.  The location must be via the file system, either on different drives or UNC.  No http or ftp.

Technorati Tags: VS2005Tip,VS2008Tip

Did you know… Visual Studio comes with an image library for you to use in your applications? – #364

Starting in Visual Studio 2005, you’ll find the Visual Studio Image Library, a zip file that contains over a 1000 images to create applications that have a consistent UI look and feel to Windows, Office, and Visual Studio.

During the Visual Studio setup, the VS2008ImageLibrary.zip file is installed at \Program Files\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary\

Visual Studio Image Library

In addition, there’s a set of folders which contain “cut sheets” or basic elements in various sizes that can be used to construct new images using any image editor that utilizes “layers”, such as Paint.NET, Photoshop or Paintshop Pro.  (please don’t ask me about these “cut sheets”, as I’m just relying the message.)

There’s a restriction on the use of the images or common elements that they must be used consistently with the definitions that are found in the readme in each folder. For example, the Visual Studio Class icon must always be used to depict the programming construct of class, and not to represent an unrelated command like “Build Project.”

Technorati Tags: VS2005Tip,VS2008Tip

Did you know… You can customize how search results are displayed in the Find Results window? – #363

Argh! I wish I had found this one in time for the book. A second edition, maybe? I’d hate to be known as a one-hit wonder. I’m sure there are more people who could use scholarship money.

Ever did a Find in Files and was annoyed that Visual Studio showed the entire file path, forcing you to scroll over just to see the name of the file and the search result?

Find Results 1 before registry change

Here’s what you can do, among some other tweaks. Note: These involve modifying registry settings. Please use at your own risk! Also Note:  You don’t have to restart Visual Studio to pick up on your registry changes. Sweet!!!

  1. Go to HKCU\Software\Microsoft\VisualStudio\9.0\Find
  2. Add a new string called Find result format with a value of $f$e($l,$c):$t\r\n where

$f is the filename

$e is the extension

$l is the line

$c is the column

$t is the text on the line

Now let’s take a look at that Find Results window again:

Find Results 1 after registry change

And here’s the full list of items you can specify in the registry

Files

$p      path                       

$f      filename               

$v      drive/unc share            

$d      dir                        

$n      name                       

$e      .ext                       

Location

$l      line                       

$c      col                        

$x      end col if on first line, else end of first line

$L      span end line

$C      span end col

Text

$0      matched text               

$t      text of first line

$s      summary of hit

$T      text of spanned lines

Char

\n      newline                   

\s      space                     

\t      tab                       

\\      slash                    

\$      $                         

If you come up with a great combination of values, please leave a comment and share with the group!

Did you know… Dock your Call Stack window alongside the Solution Explorer for a better debugging experience – #362

Whenever I found a bug that required the developer to investigate on my machine, I swear the first thing each and every one of them would do was dock the Call Stack alongside the Solution Explorer.

Call Stack docked alongside Solution Explorer

If you’re dealing with call stacks only 5 lines deep, you’ll probably like the default layout – docked to the bottom.  However, if you’re dealing with call stacks 20 lines deep, you probably want to be able to see more lines without wasting your editor space.  By tab-docking the Call Stack Window alongside the Solution Explorer, you’ll be able to see many more lines in your Call Stack window without rearranging your editor.

Technorati Tags: VS2005Tip,VS2008Tip

Did you know… Ctrl+K, Ctrl+v allows you to quickly search for objects within your solution? – #361

Another good keyboard shortcut many don’t know about. I only say that because I forgot all about this one until now…

There is a command called View.ClassViewGoToSearchCombo which does exactly as it says.

image

When you press Ctrl+K, Ctrl+V, wherever you are in the IDE, your focus will jump to the Class View search combo box, so you can just start typing and searching immediately.

Class View with focus on Search Combo Box

Technorati Tags: VS2005Tip,VS2008Tip

Did you know… You can use devenv.exe /edit to open a file in an existing Visual Studio instance – #360

Visual Studio has a command line argument you can specify to open a file in an existing instance of VS.

command line example

Just run devenv /edit <filename> and the file will open in the IDE.

file opened in Visual Studio alongside other files

You could also create a VSEdit command if you find yourself using this feature a lot.  Just create a file called "VSEdit.cmd" (you can use notepad to do this) with the following:

@"devenv.exe" /edit %*

provided you already have %Program Files%\Microsoft Visual Studio 9.0\Common7\IDE added to your system PATH environment variable. And, of course, you might want to place this VSEdit.cmd in a directory that’s in your PATH or add it.

another command line example

Technorati Tags: VS2005Tip,VS2008Tip

Did you know… Ctrl+. shows a smart tag – #359

We’ve all seen smart tags before, the little line that appears whether we’re renaming something or VS wants to help us add a using statement to our code.

C# smart tag example

There are two keyboard shortcuts to invoke (show) smart tags in the editor. There’s the keyboard shortcut no one can seem to remember Alt+Shift+F10, required for consistency with Office’s smart tags. Then there’s the slightly easier to remember keyboard shortcut Ctrl+. (period)

In C# it’s cool that you can just press Ctrl+. then press Enter, and the smart tag does its job. But in VB, you have to press Ctrl+. then arrow down (to select the first item) then press Enter. Sigh, yet another accessibility bug…

VB smart tag example

The command is View.ShowSmartTag if you want to rebind to something else. the Blogosphere seems to like Alt+Down Arrow, which isn’t bound to anything in the Editor scope.

View.ShowSmartTag command

Technorati Tags: VS2005Tip,VS2008Tip

Did you know… you can display a license in the Content Installer – #358

Directly from the help documentation:

To display an End User License Agreement (EULA) in the Visual Studio Content Installer, you must embed this information in the .zip file. WinZip supports including embedded information through the Comment feature. For more information about WinZip, see http://www.winzip.com. For more information about the Comment feature, see the WinZip Help file.

Using WinZip 12.0, the Comment feature is found under View – Comment.

As soon as you run a .vsi that has this content embedded in it, you”ll see the EULA dialog box pop up.

Football is spelled s-o-c-c-e-r

Hey, i’m just saying…

Technorati Tags: VS2005Tip,VS2008Tip