我创建了一个 t4 模板,它根据我的 c# dtos 创建 typescript dto 文件。在生成过程中,我还想将生成的 ts 文件编译为 js 文件并将它们添加到解决方案中,就像保存 ts 文件时 web Essentials 为我所做的那样。
我最初的想法是以某种方式触发保存事件;
EnvDTE.DTE dte = (EnvDTE.DTE) ((IServiceProvider) this.Host).GetService(typeof(EnvDTE.DTE));
dte.OpenFile(EnvDTE.Constants.vsViewKindAny, outputFilePath);
保存文件(以触发编译),然后再次关闭它。但我无法让它发挥作用。
有人给我出个主意吗?
最佳答案
我最终按照 Ryan Cavanaugh 的建议做了,只是调用编译器。我用过Olegs tips for creating more than one output for a template将生成的文件添加到项目和 tt 模板中。
我通过以下代码启动了编译器:
<#+
void CompileTypeScriptFile(string fullFileName)
{
var process = new System.Diagnostics.Process
{
StartInfo = new ProcessStartInfo
{
FileName = "tsc.exe",
Arguments = "--target ES5 \"" + fullFileName + "\""
}
};
process.Start();
process.WaitForExit();
}
#>
关于t4 - 从 t4 模板编译 typescript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15300630/