Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 756
Akshay Khot Avatar asked May 12 '16 23:05

Akshay Khot


People also ask

How do I add a .TT file to Visual Studio?

Include the file into your Visual Studio project. In Solution Explorer, on the shortcut menu of the project, choose Add > Existing Item. Set the file's Custom Tools property to TextTemplatingFilePreprocessor. In Solution Explorer, on the shortcut menu of the file, choose Properties.

What is a TT file Visual Studio?

Template file created by Visual Studio, a software development tool created by Microsoft; contains both text blocks and control logic used for generating new text files; can be written using Visual C# or Visual Basic code; used for both runtime text generation as well as source code generation.


1 Answers

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. :)

like image 175
Tóth Tibor Avatar answered Sep 18 '22 19:09

Tóth Tibor