Share via


ITextTemplatingEngineHost.ResolveAssemblyReference Method

Allows a host to provide additional information about the location of an assembly.

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

Syntax

'Declaration
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

Parameters

  • assemblyReference
    Type: String

    The assembly to resolve.

Return Value

Type: String
A String that contains the specified assembly reference or the specified assembly reference with additional information.

Remarks

If the user has specified the optional assembly directive in a text template, the engine calls this method. This method can be called 0, 1, or multiple times, for each text template transformation. For more information, see T4 Text Template Directives.

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.

Examples

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 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 Security

See Also

Reference

ITextTemplatingEngineHost Interface

Microsoft.VisualStudio.TextTemplating Namespace

ResolveDirectiveProcessor

ResolvePath

Other Resources

Walkthrough: Creating a Custom Text Template Host