发布于 2017-08-25 23:46:35
基于你的评论。
我已经测试了该方法,并执行了以下操作:
将TextTransform.exe添加到项目文件中(通过添加现有项,将其复制并粘贴到项目文件夹中,然后引用它,或执行其他任何操作)

创建一个新的.tt文件,我的文件包含以下内容
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".txt" #>
<#
var dateTimeNow = DateTime.Now.ToString();
#>
<#=dateTimeNow#>(只会生成一个带有DateTime的简单.txt文件,以查看它是否正常工作)
在其属性Copy to Output Directory中将这两个文件- TextTemplate1.tt and TextTransform.exe -声明为Copy always。

现在我把下面的代码放在某个地方,我是用Main编写的
static void Main(string[] args)
{
File.Delete("TextTemplate1.txt"); //delete the existing file, to make sure the code does what its supposed to do
Thread.Sleep(1000); //wait for filesystem to do its job
var proc = new Process
{
StartInfo =
{
FileName = "TextTransform.exe",
Arguments = "TextTemplate1.tt"
}
};
proc.Start();
proc.WaitForExit();
}(删除了路径,因此它相对于正在执行的.exe -需要在同一目录中)
这样,您就可以成功地获得以下输出

一切正常,需要更多的信息来帮助你找到你的问题。
我的TextTransform.exe文件:

https://stackoverflow.com/questions/45864672
复制相似问题