다음을 통해 공유


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 네임스페이스