t4 - 从 t4 模板编译 typescript 文件

标签 t4 typescript envdte web-essentials

我创建了一个 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/

相关文章:

c# - T4 - TT - 在 TT 文件中使用自定义类

visual-studio - 如何在 T4 模板中获得智能感知?

javascript - 泛型错误,类型 T 上不存在变量名

typescript - 在 TypeScript 中为 Firebase Cloud Function 配置 mailgun

c# - 如何从 EnvDTE.Window 中获取 ITextBuffer?

C# 使用 T4 生成枚举

c# - 蜡 & T4 : no "Custom Tool" option

angular - agm-map 动态显示/更新标记不起作用

c# - 你能以编程方式访问 'Service Reference' 吗?

c# - T4 使用 DTE 打开生成的文件时出现 Visual Studio 序列化错误