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.