This documentation is archived and is not being maintained.

ITextTemplatingEngineHost.ResolvePath Method

Allows a host to provide a complete path, given a file name or relative path.

Namespace:  Microsoft.VisualStudio.TextTemplating
Assembly:  Microsoft.VisualStudio.TextTemplating (in Microsoft.VisualStudio.TextTemplating.dll)

string ResolvePath(
	string path


Type: System.String

The path to complete.

Return Value

Type: System.String
A String that contains an absolute path.

A directive processor can call this method if a file name does not have a path. The host can attempt to provide path information by searching specific paths for the file and returning the file and path if found

This method can be called 0, 1, or multiple times, for each text template transformation. For more information, see Directive Syntax (Domain-Specific Languages).

A host can search for the assembly in different locations, in the order it prefers, or add a path of its choosing to the start of the assembly reference.

The following code example shows a possible implementation for a custom host. This code example is part of a larger example. For the complete example, see Walkthrough: Creating a Custom Text Template Host.

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;