Is it possible to use the asp templating engine (With the partial code-behind class, dynamic <% ... %> blocks and such) to generate non HTML? I want to have a clean and maintainable way to generate code dynamically. (Specifically, I want to generate LaTeX code populated with values from a database.)
Currently my LaTeX templates are resource strings with placeholders that I string.replace with the database values. This solution rapidly became very difficult to maintain and clean. I'd really like to use the dynamic blocks from aspx markup, but I'm not sure a) whether aspx will throw a fit when the output isn't HTML, or b) how to actually render the result into a .tex file.
The generating code itself is located in a C# .dll. We're using .NET 3.5
Is this possible? Thanks in advance.
The T4 templating that comes with Visual Studio 2008 natively or with Visual Studio 2005 SDK, you can pretty much generate anything you want.
You can have more info on the following links:
I'm pretty sure that all those links is a good start to your quest.
If you want to generate T4 templates outside of Visual Studio, there is custom MSBuild task to invoke a T4 template (link)
Here is a sample of the "Execute" code of the MSBuild task. Click here for the source code:
public override bool Execute()
{
bool success = false;
//read in the template:
string template = File.ReadAllText(this.TemplatePath);
//replace tags with property and item group values:
ProjectHelper helper = new ProjectHelper(this);
template = helper.ResolveProjectItems(template);
//copy the template to a temp file:
this._tempFilePath = Path.GetTempFileName();
File.WriteAllText(this._tempFilePath, template);
//shell out to the exe:
ProcessHelper.Run(this, TextTransform.ToolPath, TextTransform.ExeName, string.Format(TextTransform.ArgumentFormat, this.OutputPath, this._tempFilePath));
success = true;
return success;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With