Is there a way to programmatically run T4 text templates from code? I'm making a custom domain specific language and I would like the related text templates to run every time the user saves. Currently, this is what I do in the DSL model:
protected override void OnDocumentSaved(EventArgs e)
{
IVsCommandWindow commandWindow = (IVsCommandWindow)this.ServiceProvider.GetService(typeof(IVsCommandWindow));
if (commandWindow != null)
{
commandWindow.ExecuteCommand("TextTransformation.TransformAllTemplates");
}
base.OnDocumentSaved(e);
}
This works, but it has a really annoying side-effect. If the project has multiple DSL-documents, each with their related text templates, they will all be run, not just the ones that are affected by changes to the given DSL-document. This may not seem like such a big deal, but it causes source control to check out all the generated files, and if you have a lot of the documents, the transformation might actually take quite a while. Thanks for any help.
Jean-Mark Prieur from the DSL team explains how to do this with a custom tool in Part 4 of the DSL Tools Lab. You can also do this directly from the DSL model using ITextTemplating service. More on how template transformation works here.
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