How to handle T4 string patterns?

I have the following question regarding T4 templates. A review of SomeTemplate.tt contains:

<#@ template language="C#" #> Today is <#= DateTime.Today.ToString() #> 

It is processed as follows:

  SomeTemplatest st = new SomeTemplate(); string processedText = st.TransformText(); 

Q: What is this template is not existing tt and is located somewhere in the database. How can this template be treated as a string?

+4
source share
1 answer

Despite my comment on your question, in both cases you need to instantiate the Microsoft.VisualStudio.TextTemplating.Engine class. This class has a ProcessTemplate(...) method that you can pass to a template template that will be converted as a string.

The second parameter can be more complex since the template node provides contextual information and functions for transforming the template. I'm not sure if there is a way to get TextTemplatingEngineHost Visual Studio.

But for the stand-alone version of the post-assembly (for example, you want to convert templates to your application), you need to create your own text template node. A step-by-step guide on how to do this can be found here: http://msdn.microsoft.com/en-us/library/bb126579.aspx

+2
source

All Articles