Search code examples
asp.net-mvcrazorwebformstemplate-enginespark-view-engine

What's a good templating engine for a .NET console app?


We're looking for a fast, flexible way of generating templated content (in this case personalized e-mails in text and HTML format) from a .NET console application.

We have no VirtualPathProvider and no valid HttpContext.Current, which, from our initial experiments, means it's going to be very, very hard to use the WebForms view engine, and any of the other .NET web view engines (Spark, Razor) are going to need extensive plumbing to make them think they're running in a web app.

I want to do something like:

var customerTemplateData = GetTemplateDate(customer);
var htmlBody = templateEngine.Render("template.html", customerTemplateData);
var textBody = templateEngine.Render("template.txt", customerTemplateDate);
SendMail("me@mydomain.com", customer.Email, "Hey there!", htmlBody, textBody);

and I want to do it with complex nested data, lots of lists inside lists, up to 1,000 times a minute.

Any recommendations for dedicated template engines or for ways to run the Web view engines in a standalone context would be most appreciated :)

Thanks,

Dylan


Solution

  • If you're looking for some guidance on how you'd achieve this with Spark, there is a fully functional Email and Text Templating Sample available here in the Spark source code.

    It should be noted that there is actually no dependency that this sample has on HttpContext or any other web infrastructure for that matter. It's completely independant and could just as easily run as a console application.

    Hope this helps,
    All the best,
    Rob