Mike Pateras
Mike Pateras

Reputation: 15015

How do I modify a pre-built template?

I'm using the T4 toolbox's Linq to SQL model to generate code, and I'd like to add some serialization properties to the code that it generates. I'm not sure how to modify the generator to do this. Would I modify the actual .tt file that is installed with the toolbox? Or can I add something to the .tt file that gets created for me? Or do I have to do something else?

What's the best way, if any, to do this?

Upvotes: 1

Views: 271

Answers (2)

Chris Melinn
Chris Melinn

Reputation: 2076

You may already realize, but you can also create your own .tt file as well. There is nothing special about the pre-built .tt in the toolbox.

In other words, you can copy/paste/modify your own version, or even just add a new .tt file to your project. Once you save a .tt file, it automatically tries to generate code basic on the attributes specified in the tt template.

Upvotes: 1

Robert Harvey
Robert Harvey

Reputation: 180908

Yes, you can modify the .tt file. It's not a great experience, because Visual Studio doesn't do any syntax highlighting; however, Clarius has a product that you can install that will add syntax highlighting to the templates.

In Scott Hanselman's File/New/NerdDinner talk, he discusses the use of T4 templates used in the code generation for ASP.NET MVC, and demonstrates how they can be modified. The discussion about T4 templates begins at 23 minutes and 40 seconds into the talk.

Upvotes: 1

Related Questions