June 20th, 2023
heart6 reactions

Introducing the New T4 Command-Line Tool for .NET

Senior Software Engineer

We’re happy to announce that Visual Studio 2022 v17.6 now includes an updated Text Template Transformation Toolkit (T4) command-line tool built with .NET 6.

For those unfamiliar, T4 is a powerful framework that allows you to automate the creation of text files. It’s perfect for automating the creation of HTML, XAML, or even code models from REST APIs. These template files can contain invokable .NET code and string literals, so it’s critical that our users are able to utilize the latest .NET 6+ features and libraries.

Try It

Using the new TextTransformCore.exe utility is simple: all arguments are the same as TextTransform.exe. The location of the new utility is also the same and can be found under {VS_INSTALL_PATH}\Common7\IDE\TextTransformCore.exe.

Feedback

We want to hear from you! Please file feedback or issues in our Developer Community.

Additionally, there are a few questions we have about how best to support our T4 users who wish to use .NET (Core) libraries, so we’ve prepared a short survey.

Limitations

We currently do not yet support in-IDE or MSBuild task file generators for .NET 6+. However, if your template does not rely on invoking in-IDE services you can work around this by using the new TextTransformCore.exe with the Exec command.

Here’s an example, as a PreBuild step:

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="'$(DevEnvDir)TextTransformCore.exe' '$(ProjectDir)MyFile.tt'" />
</Target>

Known issues

There’s currently a known issue where transforms will fail when setting the attribute hostSpecific to true. If you do not use this.Host we recommend that you set the attribute hostSpecific="false". This issue only applies to TextTransformCore.exe.

Thanks for your patience — we’re excited to see how you utilize these new T4 capabilities.

Author

Mike Corsaro
Senior Software Engineer

24 comments

Discussion is closed. Login to edit/delete existing comments.

Sort by :
  • Chris Dailey · Edited

    This goes a long way towards what I'm really hoping for: a modernization of T4. I've voted on dev community tickets related, and really thought I'd never see any progress, so this news is most welcome.

    I specifically hope to see first class IDE support, but even just MSBuild ("TextTemplatingFileGenerator" upgrade/replacement) integration would go a long way towards easing pain points, making T4 once again a fantastic tool worth leaning on.

    Edit to add: With the inability to set hostSpecific to true, what is most convenient way to pass things from the command line?

    Read more
    • Marco GoertzMicrosoft employee

      Could you please tell us a bit more about what you mean by “MSBuild (“TextTemplatingFileGenerator” upgrade/replacement) integration would go a long way towards easing pain points”?

  • AVATAR Jake

    Yes, really need intellisense and syntax highlight.

  • Andrej Tozon

    While I’m porting all my T4 scripts to use the new Source Generators, I’m wondering if you’re resurrecting T4 or just supporting existing users… I loved T4, but lack of tooling and more output options made it quite difficult to use with time.

  • Podbielski, Natan (External)

    So it is working only on Windows?

    • Marco GoertzMicrosoft employee

      At the moment, yes. This is a CLI tool bundled with Visual Studio.