T4 vs CodeDom vs Oslo

2.5k views Asked by At

In an application scaffolding project on which I'm working, I'm trying to decide whether to use Oslo, T4 or CodeDom for generating code. Our goals are to keep dependencies to a minimum and drive code generation for a domain driven design from user stories. The first step will be to create the tests from the user stories, but we want the domain experts to be able to write their stories in a variety of different media (e.g. custom app, Word, etc.) and still generate the tests from the stories.

What I know so far:

  1. CodeDom requires .NET but can only output .NET class files (e.g. .cs, .vb). Level of difficulty is fairly high.
  2. T4 requires CodeDom and VS Standard+. Level of difficulty is fairly reasonable, especially with the T4 Toolbox.
  3. Oslo is very new. I have no idea of the dependencies, but I imagine you must be on at least .NET 3.5. I'm also not certain as to the code generation abilities or the complexity for adding new grammars. However, domain experts could probably write user stories in Intellipad quite easily. Also not sure about ease of converting stories in Word to an MGrammar.

What are your thoughts, experiences, etc. with any of the above tools. We want to stick with Microsoft or open source tools.

5

There are 5 answers

2
Scott Weinstein On BEST ANSWER

Go with T4 - easy decision.

  • Oslo is too new and the tools are too raw to be anything than an eval-only technology
  • CodeDOM is powerfull, if you need to generate CLR classes at run-time, and are willing to sacrifice easy modification to your generated output.
  • T4 (with the T4 toolkit) is a easy to use general purpose code generation tool. Only difficulty I've had so far is in build-time integrations.
3
Rine le Comte On

Generally speaking I see code generation as part of a complete modeling/coding story. It should be accompanied by a generic framework in which most of the plumbing is done. In my opinion it is not useful to generate huge classes whereas a decent framework with well-defined extension points or hooks will be much better to maintain and to extend.

You will need to define some formalized language for the user stories, be it XML or an Oslo domain language. Oslo would require your domain experts to learn the Oslo tooling. You could use Word + XML. Then you define a good-looking template in Word, with an embedded XML schema and after the story is written you can get it from Word in formalized XML syntax.This XML can of course be used to drive generators, via XSLT or Linq.

CodeDOM is powerful, but rather cumbersome. It is IMHO not an easy to use solution and it does not have real template support.

I have no experience with T4, but its templating features are a pre.

The Oslo product is indeed quite new, requires .Net 4.0, a runtime environment. It is still only a CTP. It is a very powerful environment, although I have some doubts about the database generation story.

Hope this helps.

0
Lars Corneliussen On

Well, Oslo does not fit the list. It has no code generation story so far. So stick with T4.

0
AudioBubble On

Oslo has not the intention to generate code for you. You will have to create a runtime (C# program for example) that changes it behavior depending on the data. You can see it like an internet browser.

I don't believe that Oslo requires a .Net 4.0, like Rine mentions. For my internship at Avanade Netherland I’m creating Oslo MSchema and MGrammars and a C#3.5 runtime. Depending on the given data it will creating (not generating) WCF services and run those.

0
Karel Frajták On

There are some interesting application of Oslo

  • the "new LDAP" System.Identity, more in PDC session video http://microsoftpdc.com/Sessions/SVC28
  • System.Modelling (I think) Microsoft.UML2 where you can push informations about methods, classes, modules etc. in the Repository, analyze it and create reports. For example create report with methods added/removed between 2 buils http://microsoftpdc.com/Sessions/SVR19
  • and of course modelling