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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。
請參閱
參考
Microsoft.VisualStudio.TextTemplating 命名空間