From your question, it seems you are just using T4 in a regular template file in your solution. In this case, you can simply use the <#@ include #> directive to pull out your shared code. This is a mechanism for including text, akin to C / C ++ #include , so you can move as much or less as you want to share with other files.
See the docs here .
It is worth noting that currently the include directive does not work in ASP.Net view templates.
If you want to share the code with your regular C # project, this is possible, but you need to assemble the common code into an assembly that you can reference. You cannot just use the <#@ include #> directive to pull the .cs file directly, because directives are not embedded inside control blocks or classes.
You can reference an auxiliary assembly containing your shared code using the <#@ assembly #> directive registered here .
Garethj
source share