Compartilhar via


Reference3.StrongName Property

Definition

Gets whether the reference is signed with a public/private key pair.

public:
 property bool StrongName { bool get(); };
public:
 property bool StrongName { bool get(); };
[System.Runtime.InteropServices.DispId(15)]
public bool StrongName { [System.Runtime.InteropServices.DispId(15)] get; }
[<System.Runtime.InteropServices.DispId(15)>]
[<get: System.Runtime.InteropServices.DispId(15)>]
member this.StrongName : bool
Public ReadOnly Property StrongName As Boolean

Property Value

A boolean value indicating whether the reference is signed with a public/private key pair.

Implements

Attributes

Examples

This example adds an Assembly and a COM reference to an open Visual Basic or Visual C# project. It then determines if the assembly reference has a strong name. For the COM reference, StrongName is false. 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 added reference 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)  
    DisplayStrongNameValue(applicationObject)  
End Sub  
Sub DisplayStrongNameValue(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 strong name value.  
    Dim newRef As Reference3  
    ' Replace the <file path> with an actual file path.  
    newRef = CType(aVSProject.References.Add("<file path>\adodb.dll"), _  
    Reference3)  
    MsgBox("Added an assembly reference, named: " & newRef.Name)  
    MsgBox("The StrongName value of " & newRef.Name & " is " _  
    & newRef.StrongName.ToString())  
    ' Add a COM reference and display its strong name value.  
    ' Replace <file path> with an actual file path.  
    newRef = CType(aVSProject.References.Add  
("<file path>\spcommon.dll"), Reference3)  
    MsgBox("Added a COM reference, named: " & newRef.Name)  
    MsgBox("The StrongName value of " & newRef.Name & " is " _  
    & newRef.StrongName.ToString())  
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;  
    DisplayStrongNameValue(((DTE2)applicationObject));  
}  
public void DisplayStrongNameValue(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 strong name value.  
    ' Replace the <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 StrongName value of " + aRef.Name + " is "  
+ aRef.StrongName.ToString());  
    // Add a COM reference and display its strong name value.  
    ' 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 StrongName value of " + aRef.Name + " is "  
+ aRef.StrongName.ToString());  
}  

Remarks

The returned value depends on the reference type.

Reference Type Value Returned
Assembly True if the reference has a strong name.
COM False; COM objects do not have strong names.

Only assemblies with strong names may be placed in the global assembly cache. For more information on strong names and the global assembly cache, see Strong-Named Assemblies, Global Assembly Cache, and Working with Assemblies and the Global Assembly Cache.

Applies to