Share via


ITextTemplatingEngineHost.ResolveAssemblyReference メソッド

ホストがアセンブリの場所に関する追加情報を提供できるようにします。

名前空間:  Microsoft.VisualStudio.TextTemplating
アセンブリ:  Microsoft.VisualStudio.TextTemplating.Interfaces.10.0 (Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll 内)

構文

'宣言
Function ResolveAssemblyReference ( _
    assemblyReference As String _
) As String
string ResolveAssemblyReference(
    string assemblyReference
)
String^ ResolveAssemblyReference(
    String^ assemblyReference
)
abstract ResolveAssemblyReference : 
        assemblyReference:string -> string 
function ResolveAssemblyReference(
    assemblyReference : String
) : String

パラメーター

  • assemblyReference
    型 : System.String
    解決対象のアセンブリ。

戻り値

型 : System.String
指定されたアセンブリ参照または指定されたアセンブリ参照と追加情報を表す String

解説

ユーザーがオプションの assembly ディレクティブをテキスト テンプレートで指定した場合、エンジンはこのメソッドを呼び出します。このメソッドは、テキスト テンプレートの変換ごとに 0 回、1 回、または複数回呼び出すことができます。詳細については、「T4 テキスト テンプレートのディレクティブ」を参照してください。

ホストは、異なる場所にあるアセンブリを必要な順序で検索したり、その選択のパスをアセンブリ参照の先頭に追加したりすることができます。

カスタム ホストを実装するコード例を次に示します。ここに示すコード例は、より長い例の一部です。コード例全体については、「チュートリアル: カスタム テキスト テンプレート ホストの作成」を参照してください。

public string ResolveAssemblyReference(string assemblyReference)
{
    //if the argument is the fully qualified path of an existing file,
    //then we are done (this does not do any work)
    //----------------------------------------------------------------
    if (File.Exists(assemblyReference))
    {
        return assemblyReference;
    }

    //the assembly might be in the same folder as the text template that 
    //called the directive
    //----------------------------------------------------------------
    string candidate = Path.Combine(Path.GetDirectoryName(this.inputFile), assemblyReference);
    if (File.Exists(candidate))
    {
        return candidate;
    }
        
    //this can be customized to search specific paths for the file,
    //or to search the GAC
    //----------------------------------------------------------------

    //this can be customized to accept paths to search as command line
    //arguments
    //----------------------------------------------------------------

    //if we cannot do better - return the original file name
    return "";
}
Public Function ResolveAssemblyReference(ByVal assemblyReference As String) As String Implements Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost.ResolveAssemblyReference

    'if the argument is the fully qualified path of an existing file,
    'then we are done (this does not do any work)
    '----------------------------------------------------------------
    If File.Exists(assemblyReference) Then
        Return assemblyReference
    End If


    'the assembly might be in the same folder as the text template that 
    'called the directive
    '----------------------------------------------------------------
    Dim candidate As String = Path.Combine(Path.GetDirectoryName(Me.inputFile), assemblyReference)
    If File.Exists(candidate) Then
        Return candidate
    End If

    'this can be customized to search specific paths for the file,
    'or to search the GAC
    '----------------------------------------------------------------

    'this can be customized to accept paths to search as command line
    'arguments
    '----------------------------------------------------------------

    'if we cannot do better - return the original file name
    Return ""
End Function

.NET Framework セキュリティ

  • 直前の呼び出し元に対する完全な信頼。このメンバーは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

関連項目

ITextTemplatingEngineHost インターフェイス

Microsoft.VisualStudio.TextTemplating 名前空間

ResolveDirectiveProcessor

ResolvePath

その他の技術情報

チュートリアル: カスタム テキスト テンプレート ホストの作成