Partager via


ITextTemplatingEngineHost.ResolveAssemblyReference, méthode

Autorise un hôte à fournir des informations supplémentaires concernant l'emplacement d'un assembly.

Espace de noms :  Microsoft.VisualStudio.TextTemplating
Assembly :  Microsoft.VisualStudio.TextTemplating.Interfaces.10.0 (dans Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll)

Syntaxe

'Déclaration
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

Paramètres

Valeur de retour

Type : System.String
A String qui contient la référence d'assembly spécifiée ou la référence d'assembly spécifiée avec des informations supplémentaires.

Notes

Si l'utilisateur a spécifié la directive assembly facultative dans un modèle de texte, le moteur appelle cette méthode.Cette méthode peut être appelée plusieurs fois, 1 fois ou 0 fois pour chaque transformation du modèle de texte.Pour plus d'informations, consultez Directives de modèles de texte T4.

Un hôte peut rechercher l'assembly dans différents emplacements, dans l'ordre souhaité, ou ajouter le chemin d'accès de son choix au début de la référence d'assembly.

Exemples

L'exemple de code suivant montre une implémentation possible pour un hôte personnalisé.Cet exemple de code est extrait d'un exemple plus développé.Pour obtenir un exemple complet, consultez Procédure pas à pas : création d'un hôte de modèle de texte personnalisé.

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

Sécurité .NET Framework

Voir aussi

Référence

ITextTemplatingEngineHost Interface

Microsoft.VisualStudio.TextTemplating, espace de noms

ResolveDirectiveProcessor

ResolvePath

Autres ressources

Procédure pas à pas : création d'un hôte de modèle de texte personnalisé