Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
CodeSmith Generator delivers strong integration within Visual Studio and ActiveSnippets are a driver toward increasing developer productivity. ActiveSnippets, at a high level, are CodeSmith Generator templates with exposure to the entire .Net Framework which you can utilize with a few keystrokes inside of Visual Studio. The output of your ActiveSnippet will be rendered right where you expanded on the code editor.

You can watch this video tutorial for more information: 

Widget Connector
width480
urlhttps://www.youtube.com/watch?v=lTrBP53aqrM
height360

 


Info
Visual Studio currently offers support for simple template based snippets. This is a great feature for simple snippets of code, however these templates do not contain any advanced logic or access to rich meta-data. For simple snippets such as creating a simple property shell without any logic, we still recommend using the Visual Studio snippet.

...

ActiveSnippet usage information can be obtained through the CodeSmith Generator Output Window. CodeSmith attempts to find the ActiveSnippet usage information using the context of the current line with focus. To display the output usage for configured ActiveSnippets you can select the Output ActiveSnippet Usage menu item or press CtrlControl+Alt+EG, CtrlControl+Alt+RU.

Notable Information

  • Executing Usage with no alias on the editor will display all ActiveSnippets.
  • Executing Usage using part of the prefix, will display a list of all ActiveSnippets starting with that prefix
    • For Example, using "t" by itself will show a list of all ActiveSnippets beginning with a "T".

Expanding an ActiveSnippet

Attempts to execute the ActiveSnippet using the context of the current line with focus.  If there is an ActiveSnippet configured and no errors, CodeSmith Generator will attempt to find the ActiveSnippet by Alias or by Name. If the ActiveSnippet is found, CodeSmith Generator will compile the template if not compiled, and then execute the template with the given arguments. The template output of the ActiveSnippet will be placed on the editor control of Visual Studio.

Syntax

Calling an ActiveSnippet is easy. Once configured, you simply have to enter the alias or name along with any argument parameters. Once you have defined the active snippet you want to expand, you just need to select the Expand ActiveSnippet menu item or press CTRL-E, CTRL-EControl+Alt+G, Control+Alt+G.

Info

If you are unsure about an ActiveSnippets usage is, you can select the Output ActiveSnippet Usage menu item or press CtrlControl+Alt+EG, CtrlControl+Alt+RU.


Info
By default the shortcut for Expanding an ActiveSnippet is CTRL-E, CTRL-EControl+Alt+G, Control+Alt+G.
Example

In the example below we will execute an ActiveSnippet with the name tp and pass it one argument parameter.

Code Block
tp Petshop.dbo.Orders

 


  • You can also access an ActiveSnippet by referring to it's full name.
  • You can use complex objects, such as a TableSchema by referring to it's fully qualified name Petshop.dbo.Orders

to execute this active snippet we will select the Expand ActiveSnippet menu item or press CTRL-E, CTRL-EControl+Alt+G, Control+Alt+G. The below screenshot shows the code which was generated by this ActiveSnippet.

...

  • If there is an error executing an already configured ActiveSnippet, usage information on the discovered ActiveSnippet will be presented. This shows the ActiveSnippet along with all of the arguments for that template.
    • Template is not valid.
      SourceTable is required.
      tp - TableProperties (.cs)
  • If CodeSmith Generator can not cannot find the desired ActiveSnippet by name or by configured alias, then a full list of all available ActiveSnippets will be presented in the CodeSmith Generator Output Window.

...