c# - Can I execute code from another file in a T4 .tt template for code generation? -


i'm using several t4 templates generate several t4 files, , of them share lot of same code, naturally make function out of , put in different file of t4 files access.

however can't seem find way, or google way use code stored in file.

is possible? , if so, there simple example of how so?

from question, sounds you're using t4 in normal template file in solution. in case, can use <#@ include #> directive pull in shared code. raw text inclusion mechanism, akin c/c++'s #include, can move or little care share other files.

see docs here.

it's worth noting that, @ present, include directive not work in asp.net view scaffolding templates.

if want share code regular c# project, possible, need build shared code assembly can reference. it's not possible use <#@ include #> directive pull in .cs file directly directives don't nest inside control or class feature blocks.

you can reference helper assembly containing shared code using <#@ assembly #> directive documented here.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -