8

このチュートリアルに従おうとしました: http://t4-editor.tangible-engineering.com/blog/how-to-generate-multiple-output-files-from-a-single-t4-template.html

Visual Studio 2015 (.Net 4.5) を使用

エラーのあるサンプル プロジェクト: http://www.filedropper.com/t4fail


次のソースを使用して Template1.tt を作成しました。

<#@ 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テンプレート ギャラリーからプロジェクトに追加しました。

次に、エラーが発生しました:

'Microsoft.VisualStudio.TextTemplating.IDebugTextTemplatingEngine' は、参照されていないアセンブリで定義されています。アセンブリ '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.Interfaces.11.0\v4.0_11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.TextTemplating.Interfaces.11.0.dll

私のプロジェクトに追加しましたが、何も変わりませんでした。


エラーは内部の次のメソッドにありました.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にあるかどうかを確認し、取得しました:

'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またはアセンブリ参照?)

そうではないようです。

4

3 に答える 3

6

<#@ template hostSpecific="true"#>

ファイルの上に.ttすべてを解決します。

于 2015-11-07T03:09:05.767 に答える