Reference3.StrongName 属性
获取指示引用是否用公钥/私钥对加以签名的值。
命名空间: VSLangProj80
程序集: VSLangProj80(在 VSLangProj80.dll 中)
语法
声明
ReadOnly Property StrongName As Boolean
bool StrongName { get; }
property bool StrongName {
bool get ();
}
abstract StrongName : bool
function get StrongName () : boolean
属性值
类型:System.Boolean
一个 boolean 值,指示引用是否用公钥/私钥对加以签名。
备注
返回的值取决于引用类型。
引用类型 |
返回的值 |
---|---|
程序集 |
如果引用有一个强名称,则为 True。 |
COM |
如果 COM 对象没有强名称,则为 False。 |
只有具有强名称的程序集才可以放在全局程序集缓存中。有关强名称和全局程序集缓存的更多信息,请参见 具有强名称的程序集、全局程序集缓存 和 使用程序集和全局程序集缓存。
示例
此示例向打开的 Visual Basic 或 Visual C# 项目添加程序集和 COM 引用。然后确定该程序集引用是否具有强名称。对于 COM 引用,StrongName 为 False。若要将此示例作为外接程序运行,请参见如何:编译和运行自动化对象模型代码示例。
所添加的引用的默认路径为:对于 adodb.dll 为 <安装根目录>\Program Files\Microsoft.NET\Primary Interop Assemblies,对于 spcommon.dll 为 <安装根目录>\Program Files\Common Files\SpeechEngines\Microsoft。请将示例中的 <file path> 替换为这些文件路径或其他适当的文件路径。
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());
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。