How to create T4 text templates(.tt) in ASP.NET core on Visual Studio 2015

10,915

It was a bug in the visual studio in the early stages.

Now, with Visual Studio 2015 Update 3 (and I think with Update 2 too) I can easily run T4 templates, even in .NET Core / ASP.NET Core projects.

If there isn't the Add > New Item > Text Template option, you can add *.tt files as simple text files.

Give it a try. :)

Share:
10,915
ak_rails
Author by

ak_rails

Striving to write beautiful code that solves real problems.

Updated on June 05, 2022

Comments

  • ak_rails
    ak_rails almost 2 years

    I want to create T4 text templates to achieve code generation. All the tutorials I found on msdn suggest following to add a new text template: Add > New Item > Text Template, (eg https://msdn.microsoft.com/en-us/library/dd820620.aspx) but I don't see that option(Text Template) there. I am using ASP.NET core 1.0.

    Is this issue related to VS2015 or ASP.NET core? If T4 templating is not supported in any of them, what's the best solution/alternative to achieve this?

    (I want to generate typescript code from C# code), similar to this tutorial http://dotnetspeak.com/2015/02/typescript-models-creation-via-t4-templates

  • ak_rails
    ak_rails almost 8 years
    Thanks for the update, appreciate it. There isn't Add > New Item > Text Template, but will try adding *.tt files. Hopefully that will work.
  • Tóth Tibor
    Tóth Tibor almost 8 years
    Let me know about your success :)
  • ak_rails
    ak_rails over 7 years
    Hey @TóthTibor and MatthiasBurger sorry for late reply, my initial attempt did not work, and due to some other reasons I haven't been able to work on this recently. I will update asap if I make progress.
  • ak_rails
    ak_rails over 7 years
    @TóthTibor and MatthiasBurger, I am able to generate text template now. Though VS 2015 doesn't give me an option to add "Text Template" file, I simply created a new file, and saved it as .tt, then it's functioning as a text template. Thanks for your help. :)
  • Wolfrevok Cats
    Wolfrevok Cats over 4 years
    November 2019, VS 2019, ASP.Net Core 3.0. It still IS a bug there.
  • Praveen
    Praveen over 3 years
    September 2020 VS community edition. Still couldn't add TT file to Web project. Just adding Manually.