0

I'm playing with this new (for me) technology that is the T4 templating. What I need to achieve, to put it simple, is a way to produce the text of an email, letting the user customize the text inside the mail, but having some "placeholder" that will be substitute at runtime. This sounds to me a task in which T4 runtime templating should be a good choice. Indeed it works like a charme, except for the fact that I don't understand how to deploy the solution. I'd like to have my .tt files deployed on the production server as external files (that means not embedded in a dll file), in order to be able to simply open that file with notepad, change the text of the email, and let the system start working with the new template.

I tried both setting the build action property of the tt file to Content and setting the Copy to output property to Copy always: the first simply do nothing useful as far as I can see; the second copies both the .tt and the underlying .cs files on the bin folder.

Is there a clean way to achieve such a deploy? Does the edit of the .tt files launch a restart of the application, like when you change a web.config or similar?

themarcuz
  • 2,573
  • 6
  • 36
  • 53
  • 1
    This does not sound like what TT is meant for. Why does the conventional setting the email message body not work? – StingyJack Aug 14 '12 at 16:40
  • No? I thought TT was both for compile time templating AND for runtime templating... what use of a run time template could I do if I cannot change the text in the template without a complete redeploy? Maybe I'm missing out something... – themarcuz Aug 14 '12 at 16:41
  • 1
    While it is possible to use T4 for runtime (a few examples http://stackoverflow.com/q/2307567/16391), it sounds like you are using a over-complicated solution to a simpler problem. – StingyJack Aug 14 '12 at 16:44
  • Simple problem = Use user specified text in an email. Simple solution = set the email body property to the text they specify. There is no need to compile any code at runtime to accomplish this. – StingyJack Aug 14 '12 at 16:45
  • I'm not compiling any code. The template is a text template, not a code template. It contains something like `Dear <# User #>, we write you for this reason, bla bla bla`. So no code to compile here: just merely text templating solution. – themarcuz Aug 14 '12 at 16:50
  • In some of the comments the commenter forgets that the syntax is <#= item #>.. The item must be bound to some object. – mozillanerd Aug 14 '12 at 17:01
  • @themarcuz - then it is even more useless. Use String.Format() and set the body property. – StingyJack Aug 14 '12 at 17:55

1 Answers1

0

This isn't a supported scenario for T4.

If your scenario allows for 'fixed' templates, but variable data, then runtime T4 templates are a good solution. However, the actual template production piece of T4 is only licensed for use where Visual Studio is licensed and furthermore is neither tested or supported to run on a server or in any multi-threaded environment.

There are a whole bunch of other template libraries that are tested in broader scenarios that are probably more suitable for this specific application. Microsoft has Razor for example, which might work particularly well if you're actually producing HTML-formatted email, as it's specifically targeted to angle-bracket scenarios and very much works on the server as that is where it was designed to run.

GarethJ
  • 6,496
  • 32
  • 42