{"id":46217,"date":"2023-06-20T10:05:00","date_gmt":"2023-06-20T17:05:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=46217"},"modified":"2024-12-13T14:12:25","modified_gmt":"2024-12-13T22:12:25","slug":"t4-command-line-tool-for-dotnet","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/t4-command-line-tool-for-dotnet\/","title":{"rendered":"Introducing the New T4 Command-Line Tool for .NET"},"content":{"rendered":"<p>We&#8217;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.<\/p>\n<p>For those unfamiliar, T4 is a powerful framework that allows you to automate the creation of text files. It&#8217;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&#8217;s critical that our users are able to utilize the latest .NET 6+ features and libraries.<\/p>\n<h2>Try It<\/h2>\n<p>Using the new <code>TextTransformCore.exe<\/code> utility is simple: all arguments are the same as <code>TextTransform.exe<\/code>. The location of the new utility is also the same and can be found under <code>{VS_INSTALL_PATH}\\Common7\\IDE\\TextTransformCore.exe<\/code>.<\/p>\n<h2>Feedback<\/h2>\n<p>We want to hear from you! Please file feedback or issues in our <a href=\"https:\/\/developercommunity.visualstudio.com\/\">Developer Community<\/a>.<\/p>\n<p>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&#8217;ve prepared a <a href=\"https:\/\/www.surveymonkey.com\/r\/7HY8DV8\">short survey<\/a>.<\/p>\n<h2>Limitations<\/h2>\n<p>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 <code>TextTransformCore.exe<\/code> with the <code>Exec<\/code> command.<\/p>\n<p>Here&#8217;s an example, as a PreBuild step:<\/p>\n<pre><code class=\"language-xml\">&lt;Target Name=\"PreBuild\" BeforeTargets=\"PreBuildEvent\"&gt;\r\n    &lt;Exec Command=\"'$(DevEnvDir)TextTransformCore.exe' '$(ProjectDir)MyFile.tt'\" \/&gt;\r\n&lt;\/Target&gt;<\/code><\/pre>\n<h3>Known issues<\/h3>\n<p>There&#8217;s currently a known issue where transforms will fail when setting the attribute <code>hostSpecific<\/code> to true. If you do not use <code>this.Host<\/code> we recommend that you set the attribute <code>hostSpecific=\"false\"<\/code>. This issue only applies to <code>TextTransformCore.exe<\/code>.<\/p>\n<p>Thanks for your patience &mdash; we&#8217;re excited to see how you utilize these new T4 capabilities.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn about the new T4 text template utility built with .NET 6<\/p>\n","protected":false},"author":119837,"featured_media":46218,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685],"tags":[9,7327,7745,147],"class_list":["post-46217","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","tag-net-core","tag-t4","tag-text-templating","tag-visual-studio"],"acf":[],"blog_post_summary":"<p>Learn about the new T4 text template utility built with .NET 6<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/46217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/119837"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=46217"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/46217\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/46218"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=46217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=46217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=46217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}