Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would one use T4 to transform classes from one project into another?

Assume I have a project (say ProjectA) with a number of C# classes and that those classes do not reference any types outside of the project and that of the System.dll assembly. The classes in ProjectA may have methods, properties, fields and custom properties. Classes may also exist within different namespaces.

How would one go about using T4 to transform all those classes, including methods, properties, fields and custom attributes, from ProjectA, to a related set in another project (say ProjectB).

like image 555
bloudraak Avatar asked Nov 04 '22 06:11

bloudraak


1 Answers

Werner, you can certainly do this. A good technique is to use VS's Code Model. There's some pointers to examples here: http://blogs.msdn.com/b/garethj/archive/2009/09/25/dte-and-t4-better-together.aspx

You'd use code model to read the classes in as metadata without compiling and then generate using that metadata as input. You might want to then look at Oleg Sych's T4 Toolbox ( http://t4toolbox.codeplex.com ) to project the ouput into the secondary project.

like image 103
GarethJ Avatar answered Nov 09 '22 12:11

GarethJ