views:

43

answers:

3

I have an c# Class Library where I need some dynamic template based text. Instead of inventing my own template parser I thought I could create an aspx file in my project that is executed at runtime and, instead of viewing the output in a browser, I want a StreamReader or string object that holds the result.

Is that possible? And if yes, how do I do this?

A: 

ASP.Net is designed to be run in a web server engine - you would also have to deploy this to make it work.

ck
A: 

Calling ASPX Pages from a Library would be possible (see Cassini WebServer) but I would recommend another tool:

http://www.codeproject.com/KB/cs/T4BasedCodeGenerator.aspx

We use it in our Project - slightly adapted for our needs

Arthur
+1  A: 

You're going to struggle more than is necessary with this approach. You'd need an ASP.NET host like IIS.

Personally, I'd recommend an existing template processor. I've heard (on a Hanselminutes or DotNetRocks podcast, I think) that you might even be able to host the T4 system in your application. I'll have a look and see if I've remembered that correctly.

Update

Here's a link on hosting T4 templating in your application.

Neil Barnwell
Meanwhile I created my own little Template Engine that uses some Regex magic and Reflection to produce the desired output. But the Link could be interesting in the near future. thx.
SchlaWiener