Reference3 Interface
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Estende a Reference2 interface do VSLangProj2 namespace.
public interface class Reference3 : VSLangProj2::Reference2
public interface class Reference3 : VSLangProj2::Reference2
__interface Reference3 : VSLangProj2::Reference2
[System.Runtime.InteropServices.Guid("5021602E-2025-4299-88D2-0A92E8B41ADF")]
[System.Runtime.InteropServices.TypeLibType(4160)]
public interface Reference3 : VSLangProj2.Reference2
[<System.Runtime.InteropServices.Guid("5021602E-2025-4299-88D2-0A92E8B41ADF")>]
[<System.Runtime.InteropServices.TypeLibType(4160)>]
type Reference3 = interface
interface Reference2
Public Interface Reference3
Implements Reference2
- Derivado
- Atributos
- Implementações
Exemplos
O exemplo a seguir adiciona duas referências a um Open Visual Basic ou Visual C# Project. Em seguida, ele chama uma função, GetRefTypeName, para exibir o tipo de referência e chama uma função, ReportReferences, para exibir propriedades de referência adicionais. Para executar este exemplo como um suplemento, consulte como compilar e executar os exemplos de código de modelo de objeto de automação.
Os caminhos padrão para as referências adicionadas são: <installation root> \Program Files\Microsoft.NET\Primary Interop assemblies para adodb.dll e <installation root> \Program Files\Common Files\SpeechEngines\Microsoft for spcommon.dll. Substitua o <file path> no exemplo por esses ou outros caminhos de arquivo apropriados.
Imports VSLangProj
Imports VSLangProj2
Imports VSLangProj80
Public Sub OnConnection(ByVal application As Object,_
ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
ByRef custom As Array) Implements IDTExtensibility2.OnConnection
applicationObject = CType(application, DTE2)
addInInstance = CType(addInInst, AddIn)
AddNewReference(applicationObject)
End Sub
Sub AddNewReference(ByVal dte As DTE2)
Dim aProject As Project
Dim aVSProject As VSProject2
aProject = applicationObject.Solution.Projects.Item(1)
aVSProject =_
CType(applicationObject.Solution.Projects.Item(1).Object, VSProject2)
' Add an Assembly reference and display its type and additional
' information.
Dim newRef As Reference3
' Replace <file path> with an actual path.
newRef = aVSProject.References.Add("<file path>\adodb.dll")
MsgBox("The " & newRef.Name() & " added, is of type:" & vbCr _
& GetRefTypeName(newRef))
MsgBox("A report on " & newRef.Name() & ":" & vbCr & _
ReportReferences(newRef))
' Add a COM reference and display its type and a report.
' Replace <file path> with an actual path.
newRef = aVSProject.References.Add("<file path>\spcommon.dll")
MsgBox("The " & newRef.Name() & " added, is of type:" & vbCr _
& GetRefTypeName(newRef))
MsgBox("A report on " & newRef.Name() & ":" & vbCr & _
ReportReferences(newRef))
End Sub
Private Function GetRefTypeName(ByVal ref As Reference3) _
As String
Dim type As String
Select Case ref.Type
Case prjReferenceType.prjReferenceTypeActiveX
type = "COM"
Case prjReferenceType.prjReferenceTypeAssembly
type = "Assembly"
End Select
Return type
End Function
Function ReportReferences(ByVal aRef As Reference3) As String
Dim report As String = ""
Dim type As String
' Each entry in the ArrayList contains a label and a value.
Dim ht As System.Collections.ArrayList = _
New System.Collections.ArrayList
With aRef
ht.Add(New String() {"Name", .Name})
ht.Add(New String() {"Description", .Description})
ht.Add(New String() {"Version", -
String.Format("{0}.{1}.{2}.{3}", _
.MajorVersion, .MinorVersion, .BuildNumber, .RevisionNumber)})
ht.Add(New String() {"Location", .ContainingProject.FullName})
Select Case .Type
Case prjReferenceType.prjReferenceTypeActiveX
type = "COM"
Case prjReferenceType.prjReferenceTypeAssembly
type = "Assembly"
End Select
ht.Add(New String() {"Type", type})
ht.Add(New String() {"Culture", .Culture})
End With
Dim datas() As String
For Each datas In ht
report &= datas(0) & ControlChars.Tab & datas(1) & _
ControlChars.CrLf
Next
Return report
End Function
using System.Windows.Forms;
using VSLangProj;
using VSLangProj2;
using VSLangProj80;
public void OnConnection(object application,
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
applicationObject = (DTE2)application;
addInInstance = (AddIn)addInInst;
AddNewReference(((DTE2)applicationObject));
}
public void AddNewReference(DTE2 dte)
{
Project aProject = null;
VSProject2 aVSProject = null;
aProject = applicationObject.Solution.Projects.Item(1);
aVSProject =
((VSProject2)(applicationObject.Solution.Projects.Item(1).Object));
// Add an Assembly reference and display its type and a report.
Reference3 newRef = null;
// Replace <file path> with an actual file path.
newRef = ((Reference3)(aVSProject.References.Add(@"
<file path>\adodb.dll")));
MessageBox.Show("The " + newRef.Name + " added, is of type:"
+ "\n" + GetRefTypeName(newRef));
MessageBox.Show("A report on " + newRef.Name + ":" + "\n"
+ ReportReferences(newRef));
// Add a COM reference and display its type and a report.
// Replace <file path> with an actual file path.
newRef = ((Reference3)(aVSProject.References.Add(@"
<file path>\spcommon.dll")));
MessageBox.Show("The " + newRef.Name + " added, is of type:"
+ "\n" + GetRefTypeName(newRef));
MessageBox.Show("A report on " + newRef.Name + ":" + "\n"
+ ReportReferences(newRef));
}
private string GetRefTypeName(Reference3 refIdent)
{
string type = null;
switch (refIdent.Type)
{
case prjReferenceType.prjReferenceTypeActiveX:
type = "COM";
break;
case prjReferenceType.prjReferenceTypeAssembly:
type = "Assembly";
break;
}
return type;
}
public string ReportReferences(Reference3 aRef)
{
string report = "";
string type = null;
// Each entry in the ArrayList contains a label and a value.
System.Collections.ArrayList ht =
new System.Collections.ArrayList();
VSLangProj.Reference temp = aRef;
ht.Add(new string[] { "Name", temp.Name });
ht.Add(new string[] { "Description", temp.Description });
ht.Add(new string[] { "Version", string.Format("{0}.{1}.{2}.{3}"
, temp.MajorVersion, temp.MinorVersion,
temp.BuildNumber, temp.RevisionNumber) });
ht.Add(new string[] { "Location",
temp.ContainingProject.FullName });
switch (temp.Type)
{
case prjReferenceType.prjReferenceTypeActiveX:
type = "COM";
break;
case prjReferenceType.prjReferenceTypeAssembly:
type = "Assembly";
break;
}
ht.Add(new string[] { "Type", type });
ht.Add(new string[] { "Culture", temp.Culture });
string[] datas = null;
foreach (string[] temp1 in ht)
{
datas = temp1;
report += datas[0] + "\t" + datas[1] + "\n";
}
return report;
}
Comentários
Reference3 define os seguintes novos parâmetros:
Propriedades
| Aliases |
Obtém ou define os nomes com alias para a referência especificada. Essa propriedade se aplica somente ao Visual C#. |
| AutoReferenced |
Obtém se a referência é referenciada automaticamente pelo compilador. |
| BuildNumber |
Obtém o número de Build da referência. |
| Collection |
Obtém uma coleção de References. |
| ContainingProject |
Obtém o Project que contém a referência. |
| CopyLocal |
Obtém ou define se a referência é copiada para o caminho de compartimento local. |
| Culture |
Obtém a cadeia de caracteres de cultura de uma referência. |
| Description |
Obtém uma descrição de texto da referência. |
| DTE |
Obtém o objeto de extensibilidade de nível superior. |
| Extender[String] |
Somente para uso interno da Microsoft. |
| ExtenderCATID |
Somente para uso interno da Microsoft. |
| ExtenderNames |
Somente para uso interno da Microsoft. |
| Identity |
Obtém o identificador exclusivo da referência. |
| Isolated |
Obtém ou define se a referência COM é isolada, ou seja, não registrada com o Windows. |
| MajorVersion |
Obtém o número de versão principal da referência. |
| MinorVersion |
Obtém o número de versão secundária da referência. |
| Name |
Obtém o nome do objeto. |
| Path |
Obtém o caminho para o arquivo de referência. |
| PublicKeyToken |
Obtém o token de chave pública de uma referência fortemente assinada. |
| RefType |
Obtém o tipo de referência: assembly, COM ou nativo. |
| Resolved |
Obtém se a referência atual foi resolvida. |
| RevisionNumber |
Obtém o número de revisão da referência. |
| RuntimeVersion |
Obtém a versão do tempo de execução em relação à qual a referência foi criada. Isso é aplicável somente para referências do .NET. |
| SourceProject |
Obtém um Project objeto se a referência é um projeto. Caso contrário, ele não retorna nada (um objeto nulo). |
| SpecificVersion |
Obtém ou define se apenas uma versão específica da referência é usada. |
| StrongName |
Obtém se a referência é assinada com um par de chaves pública/privada. |
| SubType |
Define ou Obtém o subtipo do assembly. |
| Type |
Obsoleto. Incluído somente para compatibilidade com versões anteriores. Use RefType em vez disso. |
| Version |
Obtém a versão da referência especificada. |
Métodos
| Remove() |
Remove a referência do References objeto que a contém. |