从PowerShell而不是visual studio发生t4模板错误

时间:2012-04-21 04:26:08

标签: c# powershell t4

我正在尝试使用powershell来处理.tt文件。我认为它非常接近,但是我在使用visual studio时调用了一个错误,而这个错误在使用visual studio时不存在。

Powershell脚本

function DoThing
{

  $inputfile = 'D:\source\62\test.tt'

  [Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualStudio.TextTemplating") | Out-Null
  [Reflection.Assembly]::LoadFile('D:\source\62\Builder.dll') | out-null  

  $host = New-Object ("CustomHost.CustomCmdLineHost") 
  // impl ITextTemplatingEngineHost


  $server = New-Object ("Microsoft.VisualStudio.TextTemplating.Engine") 

  $server.ProcessTemplate($inputfile, $host);

}

Simple.tt模板

<#@ template language="C#" #>
<#@ output extension=".txt" #>

This content was generated from a template
in the year <#= DateTime.Now.Year.ToString() #>

从Visual Studio运行时,.tt生成文件

但是从powershell我收到了一个无用的'ErrorGeneratingOutput'

我认为问题的关键是如何在使用PowerShell时实现ITextTemplatingEngineHost,欢迎提出任何建议。

谢谢!

1 个答案:

答案 0 :(得分:1)

你可以等到有人向你提供有关如何使用微软T4引擎的建议,但就个人而言,我更喜欢直接使用Mono的开源实现,

https://github.com/mono/monodevelop/tree/master/main/src/addins/TextTemplating

编译Mono.TextTemplating和TextTransform,您将获得命令行实用程序TextTransform.exe。