How to create and use custom Live Templates in ReSharper for C#?

Asked -54 seconds ago Updated 5 hours ago 19 views

0

Visual Studio provides basic code snippets, but JetBrains ReSharper Live Templates offer much more powerful macro-driven code generation capabilities for .NET developers. Creating custom templates helps standardize repetitive code blocks like logging setup, unit test structures, or property declarations.

Steps to Create a Custom Live Template

To create a custom Live Template in ReSharper, follow these steps:

  • Open Visual Studio and navigate to ReSharper > Tools > Templates Explorer.
  • Select the C# language tab and click the New Template button on the toolbar.
  • Define your shortcut macro name (for example, logi for information logging).
  • Enter the code structure utilizing ReSharper parameters wrapped in dollar signs, such as $TYPE$ or $NAME$.

Example Code Structure

Below is an example pattern used to quickly generate a structured log message inside a C# method:

// Shortcut: logi
private void LogOperation(string operationName)
{
    _logger.LogInformation("Executing operation: {OperationName}", operationName);
}

Why Use ReSharper Live Templates?

Live Templates enable developers to maintain consistency across teams by ensuring boilerplate patterns are generated identically, reducing typos and setup time during feature development.

0 Answers


Write Your Answer