views:

288

answers:

3

I am building a product, and I need a way to generate code at the runtime. Currently, I use VB.Net (only for this and nothing else) xml literals (is that what they are called?), to create templates and create code at runtime. My question is, can I use T4 on web server in shared hosting, without VS installed, to generated code at runtime?

A: 

I don't think so.

Oleg Sych
+1  A: 

Maybe the answers to this question will help you out. http://stackoverflow.com/questions/978281/t4-without-visual-studio

However, T4 is a build-time (or design-time) tool, not a run-time tool, so it doesn't seem like the best solution for what you're trying to do.

Dennis Palmer
+1  A: 

I know this question is old, but now the answer is outdated so I thought I'd chime in. If you're using Visual Studio 2010's new preprocessed templates, you can now do this. Instead of using T4 to generate code at compile time, you use T4 to generate a generator class, and that generator class can be used at run-time. This means that T4 can be used to generate any string output, not just something you need compiled into your project - and that makes it a real replacement for tools like NVelocity.

mattmc3
@matt: could you provide a link or two?
John Saunders
Sure... unfortunately, a lot of people were writing about this when VS2010 was in beta, and not much press has been given to it since. But it's not too hard to understand once you've done one yourself. Here are some of the del.icio.us links I had from when I was learning:http://msdn.microsoft.com/en-us/library/ee844259.aspxhttp://karlshifflett.wordpress.com/2009/10/30/t4-preprocessed-text-templates-in-visual-studio-2010/http://www.olegsych.com/2009/09/t4-preprocessed-text-templates/
mattmc3
@matt: Thank you, thank you, thank you. If only we could use "Razor" style syntax in T4 templates :)
epitka