<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Visual Studio Tutor &#187; Snippets</title>
	<atom:link href="http://www.visualstudiotutor.com/tag/snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.visualstudiotutor.com</link>
	<description>Visual Studio Tutorials</description>
	<lastBuildDate>Sun, 24 Apr 2011 12:54:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Create a Snippet in Visual Studio 2010</title>
		<link>http://www.visualstudiotutor.com/2010/02/create-snippet-visual-studio-2010/</link>
		<comments>http://www.visualstudiotutor.com/2010/02/create-snippet-visual-studio-2010/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 10:20:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://www.visualstudiotutor.com/?p=18</guid>
		<description><![CDATA[Pre-2010 versions of  Visual Studio had a  snippets feature which allowed users to  save code blocks for later insertion. Visual Studio 2010 contains a numerous new snippets (especially ASP.NET snippets) and allows users to easily create their own snippets. Creating snippets in VS2008 was possible but without using third-party tools it was a tricky process. VS 2010 greatly [...]]]></description>
			<content:encoded><![CDATA[<div>Pre-2010 versions of  Visual Studio had a  snippets feature which allowed users to  save code blocks for later insertion. Visual Studio 2010 contains a numerous new snippets (especially ASP.NET snippets) and allows users to easily create their own snippets. Creating snippets in VS2008 was possible but without using third-party tools it was a tricky process.</div>
<div>VS 2010 greatly simplifies the process of creating custom snippets.</div>
<div>There are two types of snippets in VS 2010, Expansion Snippets which are inserted at the cursor and SurroundsWith Snippets which wraps around existing code.</div>
<h2>Creating a Snippet in Visual Studio 2010</h2>
<div>In this walkthrough we will create a code file header snippet.</div>
<div>
<ol>
<li> Add a new XML file to your project and name it sampleHeader.snippet (Visual Studio snippets always have the extension .snippet).</li>
<li>Right-click on the editor window and select Insert Snippet to create a basic snippet template. Since we are creating an Expansion Snippet, remove the tag : &lt;snippetType&gt;SurroundsWith&lt;/snippetType&gt;</li>
<li>Alter the Title tag to read “Code File Header.”</li>
<li>Change the Author tag to your own name.</li>
<li>Change the Shortcut tag (which is the trigger word that activates your snippet) to “vstutor”</li>
<li>Enter a description for this snippet, for example “Adds  header to the code file”.</li>
<li>Since we are creating a  C# snippet alter the Language attribute of the Code tag so it reads &lt;Code Language=&#8221;CSharp&#8221;&gt; . Snippets can be creating for any language such as Visual Basic, XML etc</li>
<li>The Code section contains the code block to be added. In this example, modify the code section till it reads:&lt;Code Language=&#8221;CSharp&#8221;&gt;&lt;![CDATA[***********************************
<p>Author: $Author$</p>
<p>Date:</p>
<p>Version:</p>
<p>Purpose:</p>
<p>***********************************</p>
<p>]]&gt;</p>
<p>&lt;/Code&gt;</li>
</ol>
</div>
<p>The  finished version of the snippet appear as below:<br />
&lt;CodeSnippet Format=&#8221;1.0.0&#8243; xmlns=&#8221;http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet&#8221;&gt;</p>
<p>&lt;Header&gt;</p>
<p>&lt;Title&gt;Code File Header&lt;/Title&gt;</p>
<p>&lt;Author&gt;Test Author&lt;/Author&gt;</p>
<p>&lt;Shortcut&gt;vstutor&lt;/Shortcut&gt;</p>
<p>&lt;Description&gt;Adds a header to a code file&lt;/Description&gt;</p>
<p>&lt;SnippetTypes&gt;</p>
<p>&lt;SnippetType&gt;Expansion&lt;/SnippetType&gt;</p>
<p>&lt;/SnippetTypes&gt;</p>
<p>&lt;/Header&gt;<br />
&lt;Snippet&gt;</p>
<p>&lt;Declarations&gt;</p>
<p>&lt;Literal&gt;</p>
<p>&lt;ID&gt;Author&lt;/ID&gt;</p>
<p>&lt;Default&gt;Alex Mackey&lt;/Default&gt;</p>
<p>&lt;/Literal&gt;</p>
<p>&lt;/Declarations&gt;</p>
<p>&lt;Code Language=&#8221;CSharp&#8221;&gt;</p>
<p>&lt;![CDATA[</p>
<p>***********************************</p>
<p>Author: $Author$</p>
<p>Date:</p>
<p>Version:</p>
<p>Purpose:</p>
<p>***********************************</p>
<p>]]&gt;</p>
<p>&lt;/Code&gt;</p>
<p>&lt;/Snippet&gt;</p>
<p>&lt;/CodeSnippet&gt;</p>
<h2>Load Snippets into Visual Studio</h2>
<p>Before the snippet can be used it will need to be loaded in Visual Studio. It is best practice to create a folder to hold all your snippets, to do this and load the folder follow the below steps:</p>
<div>1. Copy the sampleHeader.snippet file from the VS solution to your snippets folder.</div>
<div>2. In the main menu, navigate to Tools and then Code Snippets Manager to get to the Code Snippets Manager</div>
<div>3. Select Import</div>
<div id="_mcePaste">4. Select your snippet</div>
<div id="_mcePaste">5. Click OK</div>
<div id="_mcePaste">6. Visual Studio will then prompt you to confirm you wish to place the snippet in My Code Snippets folder.</div>
<div></div>
<div id="_mcePaste">That’s it,  the custom snippet is now ready for use, try it out by typing vstutor in a code file. In the event you don&#8217;t know or remember the snippet name you can  open the snippet dialog by right-clicking in the editor and selecting Insert Snippet ( or  press Ctrl + K and then Ctrl + X to fire up the Insert Snippet enhancement  to navigate through snippets using the keyboard).</div>
]]></content:encoded>
			<wfw:commentRss>http://www.visualstudiotutor.com/2010/02/create-snippet-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

