T4Executer VS2019 Extension

When working with T4 templates in Visual Studio, you have to manually execute the custom for it to trigger the code generation. I used AutoT4 in the past (a VS2012 extension) to execute template on build time but this extension is not supported in the latest version(s) of Visual Studio.

T4Executer is open for contributions and improvements, the source code can be found here. To use, just install the extension. You can download it at the marketplace.

It is a pretty simple package, that ties execution of specified T4 templates to BuildEvents (BuildEvents interface). It’s possible to configure which templates to run before build, after build or just ignore a template completely.

Usage

You can configure T4Executer viaExtensions - T4Executer - Configure. A window will open that lists all templates found in your solutions’ projects.

Click on the template you want and specify to run before or after build by clicking the button under the list. You can also select multiple templates at a once. Templates you move to ignore will never be run, this can be useful for .tt files which don’t generate code or just hold some Class Feature Blocks or a collection of Import Directives. Note that the extension filters out .ttinclude files as this extension is mainly used for files that do not output generated code.

By default all templates are executed before your projects build event, when building or rebuilding your solution. Selecting Extensions - T4Executer - Disable will disable this default behaviour.

Timestamps

The timespamp of the generated the generated file is by default not preserved when the content of the file is not changed. There is a option to toggle this via Extensions - T4Executer - Preserve Timestamps.

I hope this helps you while working with T4 Templates in your solution. If you have any questions or feedback, please leave a comment below.