ITextTemplatingEngineHost.ResolvePath メソッド

ファイル名または相対パスを指定すると、ホストによって完全なパスが指定されるようにします。

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

構文

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

パラメーター

戻り値

型 : System.String
絶対パスを格納している String

解説

ファイル名にパスがない場合、ディレクティブ プロセッサはこのメソッドを呼び出すことができます。ホストは、ファイルの特定のパスを検索し、見つかった場合はファイルとパスを返すことにより、パス情報を提供することができます。

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

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

このメソッドは、テキスト テンプレートから呼び出すことができます。hostspecific="true" を設定する必要があります。

<#@ template hostspecific="true" language="C#" #>
<#@ output extension=".txt" #>
<#@ import namespace="System.IO" #>
<#
 // Find a path within the same project as the text template:
 string myFile = File.ReadAllText(this.Host.ResolvePath("MyFile.txt"));
#>
Content of myFile is:
<#= myFile #>

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

public string ResolvePath(string fileName)
{
  if (fileName == null)
  {
    throw new ArgumentNullException("the file name cannot be null");
  }
  //If the argument is the fully qualified path of an existing file,
  //then we are done
  if (File.Exists(fileName))
  {
    return fileName;
  }
  //Maybe the file is in the same folder as the text template that 
  //called the directive.
  string candidate = Path.Combine(Path.GetDirectoryName(this.TemplateFile), fileName);
  if (File.Exists(candidate))
  {
    return candidate;
  }
  //Look more places.
  //More code can go here...
  //If we cannot do better, return the original file name.
  return fileName;
}

.NET Framework セキュリティ

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

参照

関連項目

ITextTemplatingEngineHost インターフェイス

Microsoft.VisualStudio.TextTemplating 名前空間