And for those readers here who don't like C# for good or bad reasons, you can pretty much do the same with other languages.
Eg Ruby has ERB, usualy used for html templating but you can use it for anything. Make a command line tool that loads a a something.ext.erb file, runs it, and writes a something.ext file and you just made yourself a super powerful preprocessor that you already know how to use.
Many languages have this (eg EJS in JavaScript, PHP itself in PHP (use output buffering), EEx in Elixir, etc). I'd use this over a "learn yet another language" preprocessor language anytime.
Liquid and Jinja2 (both descendants of Django templating language) are also both used outside the web context now. For example, Conda package specs (called "recipes") are written in YAML, but are processed with Jinja2 first.
Unlike macros, T4 includes a fully-featured programming language (C#), with all the goodies like collections, cryptography, globalization, etc..