How to store code snippets in Visual Studio for re-use later

Storing code snippets in the Visual Studio Toolbox is really useful when we are preparing for a demo or tutorial. We can add snippets beforehand and then during our demo we can just double click or drag them onto the file we are editing.

Save snippets into the Toolbox

First, open the toolbox with the CTRL+ALT+X shortcut or from the View -> Toolbox menu item.

To keep things organised, right click on the toolbox and click ‘Add Tab’ and enter an appropriate name depending on what items you want to store in the tab.

To add code to your tab simply select the code block and drag it across into your tab.

In the below example I’ve added a tab called ‘ENTITY FRAMEWORK DEMO’ and have added two code snippets…

Visual Studio Code Snippets

If we right click on a snippet we have the option to rename it to something more helpful…

Code snippets can be renamed

 

Leave a Reply

Your email address will not be published. Required fields are marked *