Reference3.Identity Property
Gets the unique identifier of the reference.
Namespace: VSLangProj80
Assembly: VSLangProj80 (in VSLangProj80.dll)
Syntax
'Declaration
ReadOnly Property Identity As String
string Identity { get; }
property String^ Identity {
String^ get ();
}
abstract Identity : string with get
function get Identity () : String
Property Value
Type: System.String
The returned string depends on the reference type.
Reference Type |
Value Returned |
---|---|
Assembly |
Assembly name (assembly name without path or extension) |
COM |
The format is: "GUID\major.minor\localeid\wrappertool" For example, "{00000205-0000-0010-8000-00AA006D2EA4}\2.5\409\tlbimp" is returned for ActiveX Data Objects 2.5. |
Native |
Assembly identity of the assembly being referenced. |
Remarks
All components have a unique identifier. The Identity property gets that information. This property is unique for each reference, as an exception is raised if you attempt to add a reference with the same identity as a reference that is already in the collection. This property is suitable for indexing the Reference3 collection by using the Item method.
Examples
This example adds an Assembly and a COM reference to an open Visual Basic or Visual C# project and displays the Identity property for each. To run this example as an add-in, see How to: Compile and Run the Automation Object Model Code Examples.
The default paths for the reference added are: <installation root>\Program Files\Microsoft.NET\Primary Interop Assemblies for adodb.dll, and <installation root>\Program Files\Common Files\SpeechEngines\Microsoft for spcommon.dll. Replace <file path> in the example with these or other appropriate file paths.
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)
ShowIdentity (applicationObject)
End Sub
Sub ShowIdentity(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 identity.
Dim newRef As Reference3
' Replace the <file path> with an actual file path.
newRef = aVSProject.References.Add("<file path>\adodb.dll")
MsgBox("Added an Assembly reference, named: " & newRef.Name)
MsgBox("The Identity of " & newRef.Name & " is " & newRef.Identity)
' Add a COM reference and display its identity.
' Replace the <file path> with an actual file path.
newRef = aVSProject.References.Add("<file path>\spcommon.dll")
MsgBox("Added a COM reference, named: " & newRef.Name)
MsgBox("The Identity of " & newRef.Name & " is " & newRef.Identity)
End Sub
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;
ShowIdentity(((DTE2)applicationObject));
}
public void ShowIdentity(DTE2 dte)
{
// The first project is a Visual Basic or C# project.
VSProject2 vsProject =
((VSProject2)(applicationObject.Solution.Projects.Item(1).Object));
Reference3 aRef = null;
// Add an Assembly reference and display its identity.
// Replace <file path> with an actual file path.
aRef = (Reference3)vsProject.References.Add
(@"<file path>\adodb.dll");
MessageBox.Show("Added an Assembly reference, named: "
+ aRef.Name);
MessageBox.Show("The Identity of " + aRef.Name + " is "
+ aRef.Identity);
// Add a COM reference and display its identity.
// Replace <file path> with an actual file path.
aRef = (Reference3)vsProject.References.Add
(@"<file path>\spcommon.dll");
MessageBox.Show("Added a COM reference, named: "
+ aRef.Name);
MessageBox.Show("The Identity of " + aRef.Name + " is "
+ aRef.Identity);
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.