Recent blog posts about T4


Here are some blog posts about code generation with T4 that caught my attention in July. I hope you find them useful.

Damien Guard made several improvements in his LINQ to SQL template, including code generation based on .dbml file instead of SQL database, associations based on foreign keys and appropriate attributes.

Elton Stoneman created an MSBuild task for transforming T4 templates, which allows using MSBuild properties and items in text blocks and code blocks of the template. This also allows using T4 in Visual Studio project that are based on MSBuild but don’t support custom tools. In particular, this allows using T4 in Visual Studio Database Edition projects to generate CRUD stored procedures without having an extra C# or Visual Basic project for code generation.

Andrew Matthews wrote an article about generating state machines in C# using T4 text templates based on a state model defined in XML. It would be interesting to understand tradeoffs in using this approach compared to Windows Workflow Foundation.

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Other Posts
Extending T4: <#@ xsd #> directive
Simplifying WCF: Using Exceptions as Faults

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Hi Oleg,

The main thing we lost out on (apart from CV points :) is the use of a standardized framework. We gained excellent performance in return though. My initial performance tests showed me able to navigate all transitions on a simple state model in under 8 microseconds. (We threw it all away when we added a persistence veneer over the top of the state machine).

The main reason was that the client was already modeling their system using Visio, so it made sense to capitalize on that to derive the application structure.

One thing that did bother me was the tendency of T4 to lock those assemblies that it uses to parse the input files within VS 2008. I ended up having to use pre-build generation using the command-line tool.

I’ve been quite impressed with T4. It’s as easy or simpler than (e.g.) NVelocity or StringTemplate.

Regards,

Andrew