views:

62

answers:

2

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?

+1  A: 

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.

Robert Harvey
So I modify the pre-built model template itself, not the file that the toolbox created for me (essentially a blank .tt file that references the model)? That would make sense, I just thought there might be a way to modify the local .tt file, and not mess with the pre-built template.
Mike Pateras
+1  A: 

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.

Chris Melinn