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.
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...
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”?
Yes, really need intellisense and syntax highlight.
Please upvote the following ticket for that if you haven’t done so already. Thanks!
https://developercommunity.visualstudio.com/content/idea/835882/t4-template-editor-with-markup-and-intellisense.html
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.
Yes, we are making some investments in T4. Mostly for being able to run transformation using .NET (Core).
For tooling please upvote https://developercommunity.visualstudio.com/content/idea/835882/t4-template-editor-with-markup-and-intellisense.html and for the output options please tell us more about it here and/or in the short survey. Thanks!
So it is working only on Windows?
At the moment, yes. This is a CLI tool bundled with Visual Studio.
Hello. Great to see some updates to the old workhorse T4. I saw a few comments here about a dotnet tool and just FYI there's a T4 clone developed for mono back in the days that is runnable as a tool. https://github.com/mono/t4
Here's a few things I wish T4 in the future.
1. Support nuget references
2. Package t4 templates as nuget packages.
3. Basic syntax highlighting.
For me I know people are saying source generators is...
For the 3rd point, please upvote the following ticket if you haven’t done so already. Thanks!
https://developercommunity.visualstudio.com/content/idea/835882/t4-template-editor-with-markup-and-intellisense.html
Am I alone who doesn't understand why you wrote "TextTransformCore.exe", having WORKING "TextTransform.exe"???
You have TONS of tasks, but instead you write hell knows what, wasting time and money. VS for 20 years(!!!) lacks syntax highlight for *.tt files - who and why still not implement it? In C# islands you have nothing - no highlight, no intellisense. It's not more complex than ASP files (which HAVE support).
MS disappoints me more and more with every single...
Hello! There were a few reasons why we needed to create a separate .NET 6 version of the TextTransform utility beyond the reason of it being one of our highest voted issues:
Regarding syntax highlighting -- this is something we'd like to implement, and I recommend that you vote on or create an issue in the community forums for visibility.
T4 rises from the dead! Super-exciting to see you guys resurrect T4 and start to modernize it.
I hope you will be able to make it open source and figure out some of the portability issues (the biggest one in my mind was always how to figure out the project root without VS).
I gave up on T4, due to Visual Studio’s complete lack of editor support for the files. I switched to just using regular WriteLine() statements in normal code for generating code.
For editor support, please upvote the following ticket if you haven’t done so already. Thanks!
https://developercommunity.visualstudio.com/content/idea/835882/t4-template-editor-with-markup-and-intellisense.html
Why is it in /dotnet blog? It’s neither open-source, part of .NET SDK, or supported by dotnet tooling. It’s a Visual Studio exclusive feature. Move it to Visual Studio blog then. Why isn’t it open sourced? So much work to update, why not share with community to enable porting for cross-platform usage, be open for community enhancements, performance improvements, and so much other good stuff.
Cool. Why not make it a dotnet CLI tool? Something like
dotnet t4 mytemplate.tt
.FWIW there is a .NET CLI tool for T4, though it uses a different T4 implementation – https://www.nuget.org/packages/dotnet-t4/
I would encourage you to go to https://developercommunity.visualstudio.com/, request a new feature, and respond back here with the link to the ticket. That way others can upvote, we can get this officially tracked, and we can provide you with a better way for updates and further communication. Thanks!
Hello! Thanks for bringing that up — it’s something we’ll seriously consider for sure.
In the process of modernising our toolchain from .NET Framework to .NET out CI/CD process (in GitHub Actions) is entirely based on pulling in .NET Global Tools. The days of having a build image with Visual Studio (in order to access all the tools) are thankfully long gone! It feels much more like the GO / Rust approaches.
Like this one https://www.nuget.org/packages/dotnet-t4/ ? Actually you can use it for a long time in .NET world