ITextTemplatingEngineHost.ResolveAssemblyReference 方法

允许主机提供有关程序集位置的附加信息。

命名空间:  Microsoft.VisualStudio.TextTemplating
程序集:  Microsoft.VisualStudio.TextTemplating.Interfaces.10.0(在 Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll 中)

语法

声明
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

参数

  • assemblyReference
    类型:System.String
    要解析的程序集。

返回值

类型:System.String
一个 String,其中包含指定的程序集引用或指定的程序集引用以及附加信息。

备注

如果用户在文本模板中指定可选的 assembly 指令,该引擎将调用此方法。 对于每个文本模板转换,可以调用此方法 0 次、1 次或多次。 有关更多信息,请参见 T4 文本模板指令

主机可以在不同位置按它想要的顺序搜索程序集,或者添加程序集引用开始的选择路径。

示例

下面的代码示例演示了自定义主机的可能实现。 此代码示例摘自一个更大的示例。 有关完整的示例,请参见演练:创建自定义文本模板宿主

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 安全性

请参见

参考

ITextTemplatingEngineHost 接口

Microsoft.VisualStudio.TextTemplating 命名空间

ResolveDirectiveProcessor

ResolvePath

其他资源

演练:创建自定义文本模板宿主