tags:

views:

1500

answers:

3

Has someone ported the netTiers template set to Visual Studio's T4 templates? Or is there a system of similar scope? Does anyone use T4 in a work environment? What (if any) major differences are there between Codesmith and T4?

+2  A: 

I dabbled in T4 for a bit - hey, if it's free and included in VS2008, use it, right?

My basic idea was to create a set of templates to read a database table, and create our own "roll-your-own" ORM classes from it.

I gave up on T4, frustrated and unable to get even the most basic things to work that are a piece of cake in CodeSmith.

Even a simple task such as selecting what server, database, and table to use cannot be done in T4 efficiently from "outside" the template itself. Yes, you can hard-code all these values as string values into a T4 template - but c'mon, that's really not a solution, is it?

CodeSmith has great support for picking server, database, and tables, and you can set those as properties on the template and just pick what you want and let the template do your stuff on that particular table you picked.

My conclusion: T4 is promising, but "not there" just yet. It might work for very simple scenarios, but right now, it's in my opinion nowhere near as flexible and powerful as Codesmith.

For for a scenario such as .netTiers, I'd stick with Codesmith for the time being.

Marc

marc_s
You could of course have settings in a separate template and just include it in your main generation template. This way, your settings file will be small and everything will be contained in a single file. Could be called `settings.tt`
Robert Koritnik
@Robert: sure - but that doesn't solve the fundamental problem - there's no easy way to pass parameters to T4 templates right now - a **MAJOR** drawback in my opinion
marc_s
+3  A: 

T4 is not CodeSmith. Yes, you specify parameters in a .tt file in the form of C# or Visual Basic code and use an <#@ include #> directive to reference the actual implementation of the code generation logic. This is not more hard-coding than specifying the same information in an XML file with CodeSmith.

For a NetTiers-like suite of T4 templates, check out S#arp Architecture: http://code.google.com/p/sharp-architecture/.

Oleg Sych
A: 

If you are looking for a T4 implementation of a well supported DAL that is Open Source with a Linq interface as well as its own Fluent interface that will create wrappers for Tables, Stored Procs, Views etc. Then you need to try SubSonic 3.0. SubSonic 2.2 has the same goodness minus the T4 and the Linq interface and is in release mode. SubSonic 3.0 is in Alpha but you can download the code or a .dll and the T4 templates if you like.

runxc1 Bret Ferrier