2012-04-21 65 views
1

我試圖使用powershell來處理.tt文件。我認爲它非常接近,但是在使用Visual Studio時,我從PowerShell中調用了一個不存在的錯誤。t4從powershell發生模板錯誤不是視覺工作室

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,歡迎在此提出任何建議。

謝謝!

回答

0

你可以等待,直到有人爲您提供如何使用微軟的T4引擎,但個人而言,我更喜歡直接使用Mono的開放源代碼實現的建議,

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

編譯Mono.TextTemplating和TextTransform你得到一個命令行實用程序TextTransform.exe。

+0

感謝您的評論,我認爲事情的t4方面是好的,因爲在一個主機模板運行良好,但沒有其他。一個命令行應用程序與相同的ITextTemplatingEngineHost DLL工作正常,所以似乎有可能有一種方法。 – MikeW 2012-04-21 09:29:16