Setting Up for Use of Microsoft Symbol Server

When debugging native Win32 code, it is useful to have the debug symbols for all of Microsoft's DLLs. The easiest way to set this up is to just set an environment variable before starting Visual Studio (or other Microsoft debugging tools):

set _NT_SYMBOL_PATH=srv*c:\symbols*

The first time you run the debugger after setting this, it will take some time to start as it downloads symbol files from the Internet into your local symbol cache, but it will be faster after that. Whenever you update your system with patches or service packs, the new symbols will automatically be downloaded the next time you debug.

For more information, see these pages:

(This post is really for my own benefit. I have trouble finding this information whenever I set up a new development workstation, so I'm putting it somewhere I'll know to look.)

Visual Studio 2008 Code Snippet for Inserting a String.Format() call

Over the past year I've been (re-)learning how to use Visual Studio 2008. I did a lot of work in the 90's and early 00's with Visual Studios 5, 6, and 2003, but then I had a few years away from Windows development, and I've had limited experience with .NET development. So I'm constantly discovering "new things" about Visual Studio that my coworkers already know.

One nifty feature of Visual Studio is "code snippets", which are basically little bits of code that can be quickly inserted into a source file using Intellisense. The inserted code includes placeholders that can be replaced with whatever you need. For example, if you are typing away in a C# source file and type the keyword for, you'll see the Intellsense window pop up with "for" as the selected item, and if you hit the Tab key a couple of times a complete for statement with braces, a loop variable, and everything will be inserted. You can then hit Tab to move to the loop variable name (in case you don't like i) and again to go into the loop body.

(Other IDEs have similar features, calling them abbreviations, macros, etc. You don't need to tell me that Visual Studio isn't magically unique.)

Visual Studio has a whole bunch of these snippets built in, but you can also define your own by writing an XML file and saving it where Visual Studio can find it. For example, here is a snippet I wrote to quickly insert String.Format() expressions:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="">
  <CodeSnippet Format="1.0.0">
      <Description>Creates a String.Format() call</Description>
      <Author>Kristopher Johnson</Author>
          <ToolTip>Replace with format string</ToolTip>
          <ToolTip>Replace with arguments</ToolTip>
      <Code Language="CSharp">
        <![CDATA[String.Format("$format$", $arguments$)$end$]]>

Just save this as a file called StringFormat.snippet in your Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets folder. (You can specify another location using the Code Snippets Manager in the Tools menu.) Then, when editing a C# source file, if you type sf and hit Tab a couple of times, this will magically appear in your code:

String.Format(" format ", arguments )

The format placeholder will be selected, so you can replace it with your format string, then hit Tab and the arguments placeholder will be selected, so you can replace it. You can keep hitting Tab to go back and forth between the placeholders. When finished, hit Return and the cursor will go to the end of the line.

Alas, snippets only work for C#, Visual Basic, and XML editing. Most of my work is in C++, so I have to keep writing code the old-fashioned way there (or use macros).

Note that I have been talking about Visual Studio 2008. "Why aren't you using Visual Studio 2010?" some will ask. Shut up.

For a more comprehensive tutorial on creating code snippets, see Switch On The Code: C# Tutorial - Visual Studio Code Snippets.

Syndicate content