Debugger.Launch() codesnippet

If you are like me, tired of writing “System.Diagostics.Debugger.Launch()”, when debugging feature receivers (or something else in Sharepoint), here´s a tip for you.
Use a code snippet (an xml file in in fact). Either you open an existing snippet (on Vista they are located here: (C:\Program Files x86\Microsoft Visual Studio 9.0\VC#\Snippets\1033 ) or create a new xml file that you give the extension of .snippet

Here´s the snippet for debugger.launch:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Debugger.Launch</Title>
            <Shortcut>dl</Shortcut>
            <Description>Code snippet for Debugger.Launch()</Description>
            <Author>Johan Leino</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Code Language="csharp">
                <!&#91;CDATA&#91;
            #if DEBUG
            System.Diagnostics.Debugger.Launch();
            #endif
                &#93;&#93;>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

The value in the Shortcut node  is what you write in VS to show your snippet (like “prop” or “ctor”), in this case “dl”.

Save your snippet to (location may differ depending on operating system):
Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets\[your name].snippet

So when you write “dl” the snippet appears and you just press TAB to insert it, like this:
image

…and

image

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: