Introducing T4 Text Template Support in Rider 2019.3
Brace yourself! Another highly requested feature request was finally resolved – Support for T4 Text Templates. For those folks who don’t know what it is: T4 stands for Text Template Transformation Toolkit – a mixture of code blocks and text that can generate new text files or even code (similar to Razor). T4 templates are very handy to generate output based on our project model or external databases. For instance, using linq2db we can easily generate POCOs based on a database schema to allow for fast and type-safe database accessing.
Many ReSharper users might be familiar with the ForTea plugin that was developed and maintained by Julien Lebosquain. A huge round of applause for his amazing work and permission to integrate it directly in Rider! Besides some minor adjustments, the most significant missing part was the generation itself. Did we mention it’s still open-source?!
How does Rider help with T4 Text Templates?
Let’s start small by adding a new T4 text template file. There are regular
.tt template files on which the generator is executed, and
.ttinclude files, which allow for code sharing:
Also a good reminder, that we can just type in the New File dialog and search for the file type we want.
As mentioned, the regular
.tt template files are meant for generation. So here we are with some actions – Execute Template and Debug Template for design-time templates, and Preprocess Template for our run-time templates:
As you may have guessed, debugging also works fluently. Just place a breakpoint, hit Debug Template, and we can use all the debugger goodies, like seeing stack traces, inspecting variables, modifying the execution pointer, and many more:
For standard control blocks, the code completion integration will let us choose from a list of available keywords:
For navigating around, we can either use the normal symbol navigation (a.k.a.
GoToFileMember) or make use of the Structure tool window:
Good old code inspections & quick-fixes can help us to see errors at a glance and fix them right away. For instance here, when a feature block was misplaced before a statement block:
And of course, it wouldn’t be Rider, if there wasn’t integration with all the other C# features that we’re familiar with, like code completion, namespace imports, live and postfix templates, formatting for control blocks, and last but not least, symbol navigation:
Pro tip on the side: as shown in the GIF above, regular strings will turn into interpolated strings if we try to use them as such. Thanks to code completion!
We’re still working on shipping additional features around T4 templates, until then, download Rider 2019.3, try it out and tell us what you think!
Subscribe to Blog updates
Creating Custom AI Prompts
AI has swept through the software development industry like a wildfire. So people want to learn how to best use AI in their day to day tasks. In this post we’ll take a look at how to write custom prompts for use with the JetBrains AI Assistant in ReSharper and Rider so you can make the most of AI.&n…
12 Debugging Techniques In JetBrains Rider You Should Know About
Twelve must know debugging features in JetBrains Rider every developer should know.
Interceptors – Using C# 12 in Rider and ReSharper
Welcome to our series, where we take a closer look at the C# 12 language features and how ReSharper and Rider make it easy for you to adopt them in your codebase. If you haven’t yet, download the latest .NET 8 SDK and update your project files! In this series, we are looking at: Primary …