共用方式為


Reference3.StrongName 屬性

取得參考是否已用公開/私密金鑰組 (Key Pair) 加上簽章。

命名空間:  VSLangProj80
組件:  VSLangProj80 (在 VSLangProj80.dll 中)

語法

'宣告
ReadOnly Property StrongName As Boolean
    Get
bool StrongName { get; }
property bool StrongName {
    bool get ();
}
abstract StrongName : bool
function get StrongName () : boolean

屬性值

型別:System.Boolean
boolean 值,指出參考是否以公開/私密金鑰組加上簽章。

實作

Reference2.StrongName

備註

視參考型別而傳回不同值。

參考型別

傳回值

組件

如果參考具有強式名稱,為 True。

COM

COM 物件沒有強式名稱,為 False。

只有具有強式名稱的組件才能放置在全域組件快取中。 如需強式名稱與全域組件快取區的詳細相關資訊,請參閱強式名稱的組件全域組件快取使用組件和全域組件快取

範例

此範例會將組件和 COM 參考加入至開啟的 Visual Basic 或 Visual C# 專案中, 然後會判斷組件參考是否具備強式名稱。 若是 COM 參考,StrongName 為 false。 若要將此範例當做增益集來執行,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例

新增的參考之預設路徑:adodb.dll 為 <installation root>\Program Files\Microsoft.NET\Primary Interop Assemblies,以及 spcommon.dll 為 <installation root>\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 安全性

請參閱

參考

Reference3 介面

StrongName 多載

VSLangProj80 命名空間