Compartir a través de


DSL 2010 Feature Dives: T4 Preprocessing - Part One - Rationale

Strictly, this isn't a DSL 2010 feature, but a general Visual Studio 2010 feature; T4 is only coupled organizationally to DSL Tools, not technically, but it fits into our current announcements, so I won't worry about that too much.

Over the last year or so, I've been fielding an increasing number of requests from folks who want to use T4 to produce output in scenarios other than at design-time inside Visual Studio.  Just to be clear, T4 in its 2008 incarnation is not suitable for use on the server, or in any concurrent, multi-threaded scenario - there's nothing specifically wrong with the code in this regard that we know of, but it's simply not tested in this arena, and we choose not to support something that hasn't been tested.  T4 also only ships inside Visual Studio SKUs, so you have some unfortunate installation and interpretation of your EULA to do if you wanted to look at using it in another scenario.

However, we're very aware of this pent-up demand, and a conversation with the Entity Framework team brought our thinking caps out.

What we came up with was an assertion that want something like the following:

In a high percentage of scenarios for using T4 at runtime (as opposed to design-time), the template only changes as part of a software installation; rather the input data for the template is changing in order to produce differing output.

For example, you can imagine T4 being used to implement some transform between EDI data and XML data in a business workflow.  It's likely that the structure of the required XML document is an implementation artifact of the workflow, whereas clearly the instance documents of the XML are directly driven by the instance of EDI data that's presented.

On this basis, we realized that if we decoupled T4's preprocessing stage from its compile and run stages, we could produce template code that could repeatably take input and produce template output that we'd be happy to support running in any .Net environment, thus enabling a lot of the scenarios that customers had asked for.

We call this feature Template Preprocessing and next time I'll describe the high level design points.

 

 

Technorati Tags: T4, DSL Tools, Domain-Specific Language, Code Generation, Visual Studio 2010

Comments

  • Anonymous
    November 20, 2008
    I've been catching up on my blog reading...interesting stuff I came across; PNRP in Windows 7 being...