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 - пространство имен
Другие ресурсы
Пошаговое руководство. Создание пользовательского хост-класса для текстовых шаблонов