如何使用有形编辑器从单个T4模板创建多个输出文件? [英] How to create multiple output files from a single T4 template using Tangible Editor?

查看:273
本文介绍了如何使用有形编辑器从单个T4模板创建多个输出文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试遵循此教程:使用Visual Studio 2015(.Net 4.5)

with visual studio 2015 (.Net 4.5)

有错误的示例项目: http://www.filedropper.com/t4fail

我使用以下来源创建了Template1.tt:

I created the Template1.tt with the following source:

<#@ include file="TemplateFileManagerV2.1.ttinclude" #>
<#@ Assembly Name="System.Core" #>
<#@ Assembly Name="System.Windows.Forms" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #> 
<#
    var manager = TemplateFileManager.Create(this);
#>

我将模板库中的TemplateFileManagerV2.1.ttinclude添加到了我的项目中.

I added TemplateFileManagerV2.1.ttinclude from template gallery to my project.

然后我得到一个错误:

"Microsoft.VisualStudio.TextTemplating.IDebugTextTemplatingEngine"为 在未引用的程序集中定义.您必须添加一个 参考组装 'Microsoft.VisualStudio.TextTemplating.Interfaces.11.0, 版本= 11.0.0.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a'.

'Microsoft.VisualStudio.TextTemplating.IDebugTextTemplatingEngine' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.VisualStudio.TextTemplating.Interfaces.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

所以我添加了对

C:\ Windows \ Microsoft.NET \ assembly \ GAC_MSIL \ Microsoft.VisualStudio.TextTemplating.11.0 \ v4.0_11.0.0.0__b03f5f7f11d50a3a \ Microsoft.VisualStudio.TextTemplating.11.0.dll

C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.TextTemplating.11.0\v4.0_11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.TextTemplating.11.0.dll

C:\ Windows \ Microsoft.NET \ assembly \ GAC_MSIL \ Microsoft.VisualStudio.TextTemplating.Interfaces.11.0 \ v4.0_11.0.0.0__b03f5f7f11d50a3a \ Microsoft.VisualStudio.TextTemplating.Interfaces.11.0.dll

C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.TextTemplating.Interfaces.11.0\v4.0_11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.TextTemplating.Interfaces.11.0.dll

进入我的项目,但没有任何改变.

to my project, but nothing changed.

错误是在.ttinclude

public string GetTemplateContent(string templateName, TextTemplatingSession session)
    {
        string fullName = this.Host.ResolvePath(templateName);
        string templateContent = File.ReadAllText(fullName);

        var sessionHost = this.Host as ITextTemplatingSessionHost;
        sessionHost.Session = session;

        Engine engine = new Engine();
        return engine.ProcessTemplate(templateContent, this.Host);
    }

我替换为

public string GetTemplateContent(string templateName, TextTemplatingSession session)
    {
        string fullName = this.Host.ResolvePath(templateName);
        string templateContent = File.ReadAllText(fullName);

        var sessionHost = this.Host as ITextTemplatingSessionHost;
        sessionHost.Session = session;

        //Engine engine = new Engine();
        return "";//engine.ProcessTemplate(templateContent, this.Host);
    }

检查问题是否确实在dll中并得到:

to check if the problem is indeed in dll and got:

'Microsoft.VisualStudio.TextTemplatingA30AC8B57EFC4307E43667FCD72F5E4857F498C5224AE0D43FFC74B3A98D4FA090794EF196648D62B1BC664AFBA5EDE831067D7D1768A759EBBE834834975975F7AA.GeneratedTextTransformation' 不包含主机"的定义,也没有扩展方法 主机"接受类型的第一个参数 'Microsoft.VisualStudio.TextTemplatingA30AC8B57EFC4307E43667FCD72F5E4857F498C5224AE0D43FFC74B3A98D4FA090794EF196648D62B1BC664AFBA5EDE831067D7D1768A759EBBE83426975F7AA.GeneratedTextTransformation' 可以找到(您是否缺少using指令或程序集 参考?)

'Microsoft.VisualStudio.TextTemplatingA30AC8B57EFC4307E43667FCD72F5E4857F498C5224AE0D43FFC74B3A98D4FA090794EF196648D62B1BC664AFBA5EDE831067D7D1768A759EBBE83426975F7AA.GeneratedTextTransformation' does not contain a definition for 'Host' and no extension method 'Host' accepting a first argument of type 'Microsoft.VisualStudio.TextTemplatingA30AC8B57EFC4307E43667FCD72F5E4857F498C5224AE0D43FFC74B3A98D4FA090794EF196648D62B1BC664AFBA5EDE831067D7D1768A759EBBE83426975F7AA.GeneratedTextTransformation' could be found (are you missing a using directive or an assembly reference?)

似乎不是.

推荐答案

<#@ template hostSpecific="true"#>

可以解决所有问题.

这篇关于如何使用有形编辑器从单个T4模板创建多个输出文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆