C# 在powershell而非visual studio中发生t4模板错误

C# 在powershell而非visual studio中发生t4模板错误,c#,powershell,t4,C#,Powershell,T4,我正在尝试使用powershell处理.tt文件。我认为这非常接近,但我从powershell调用时遇到了一个错误,在使用VisualStudio时,该错误并不存在 Powershell脚本 function DoThing { $inputfile = 'D:\source\62\test.tt' [Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualStudio.TextTemplating") | Out-Nul

我正在尝试使用powershell处理.tt文件。我认为这非常接近,但我从powershell调用时遇到了一个错误,在使用VisualStudio时,该错误并不存在

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() #>

此内容是从模板生成的
年内
从VisualStudio运行时,.tt会生成文件

然而,从powershell中,我收到了一个毫无帮助的“ErrorGeneratingOutput”

我认为问题的要点是如何在从powershell使用时实现ITextTemplatingEngineHost,欢迎您提出任何建议


谢谢

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


编译Mono.textTemplateing和TextTransform您将获得一个命令行实用程序TextTransform.exe。

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


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

感谢您的评论,我认为t4方面的问题很好,因为模板在一台主机上运行良好,但在另一台主机上运行不好。命令行应用程序与相同的ITextTemplatingEngineHost dll配合良好,因此似乎有办法。感谢您的评论,我认为t4方面很好,因为模板在一台主机上运行良好,但在另一台主机上运行不好。命令行应用程序可以与相同的ITextTemplatingEngineHost dll配合使用,因此似乎有可能找到一种方法。