Condividi tramite


Metodo ITextTemplatingEngineHost.ResolveAssemblyReference

Consente a un host di fornire informazioni aggiuntive sulla posizione di un assembly.

Spazio dei nomi:  Microsoft.VisualStudio.TextTemplating
Assembly:  Microsoft.VisualStudio.TextTemplating.Interfaces.10.0 (in Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll)

Sintassi

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

Parametri

Valore restituito

Tipo: System.String
In String che contiene il riferimento all'assembly specificato o il riferimento di assembly specificato con informazioni aggiuntive.

Note

se l'utente ha specificato il facoltativo assembly la direttiva nel modello di testo, il motore chiama questo metodo.Questo metodo può essere chiamato 0, 1, o più volte, per ogni trasformazione del modello di testo.Per ulteriori informazioni, vedere Direttive di modello di testo T4.

Un host può individuare l'assembly in posizioni diverse, nell'ordine preferisce, o aggiunge un percorso relativo scegliere nella parte superiore del riferimento all'assembly.

Esempi

Nell'esempio di codice seguente viene illustrata un'implementazione anche un host personalizzato.Questo esempio di codice fa parte di un esempio più esaustivo.per l'esempio completo, vedere Procedura dettagliata: creazione di un host del modello di testo personalizzato.

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

Sicurezza di .NET Framework

Vedere anche

Riferimenti

ITextTemplatingEngineHost Interfaccia

Spazio dei nomi Microsoft.VisualStudio.TextTemplating

ResolveDirectiveProcessor

ResolvePath

Altre risorse

Procedura dettagliata: creazione di un host del modello di testo personalizzato