VSProject2.GenerateKeyPairFiles 方法 (String, String)

產生公開金鑰 (Public Key)/私密金鑰 (Private Key) 檔案,用來形成組件的強式名稱 (Strong Name)。

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

語法

'宣告
Sub GenerateKeyPairFiles ( _
    strPublicPrivateFile As String, _
    strPublicOnlyFile As String _
)
void GenerateKeyPairFiles(
    string strPublicPrivateFile,
    string strPublicOnlyFile
)
void GenerateKeyPairFiles(
    [InAttribute] String^ strPublicPrivateFile, 
    [InAttribute] String^ strPublicOnlyFile
)
abstract GenerateKeyPairFiles : 
        strPublicPrivateFile:string * 
        strPublicOnlyFile:string -> unit 
function GenerateKeyPairFiles(
    strPublicPrivateFile : String, 
    strPublicOnlyFile : String
)

參數

  • strPublicPrivateFile
    型別:System.String
    要產生的檔案名稱。
  • strPublicOnlyFile
    型別:System.String
    若為 true,只會產生公開金鑰。

實作

VSProject.GenerateKeyPairFiles(String, String)

備註

強式名稱是由組件的識別 (它的簡單文字名稱、版本號碼和文化特性資訊 (如果有)) 加上公開金鑰和數位簽章所構成。 公用/私密金鑰組是用來建立數位簽章的,可儲存於檔案或密碼編譯服務提供者的容器中。 Sn.exe (強式名稱工具) 會建立檔案或容器。 容器名稱是在執行工具時由使用者指定的,而這個屬性中也使用相同的名稱。 如需詳細資訊,請參閱強式名稱的組件

密碼編譯服務提供者是一種獨立的軟體模組,負責執行密碼編譯演算法來進行驗證 (Authentication)、編碼和加密 (Encryption)。 如需詳細資訊,請參閱Cryptographic Services

範例

此範例會產生內含金鑰組 (Key Pair) 的二進位檔案 (Binary File)。 若要檢視產生的檔案,請使用Sn.exe (強式名稱工具)。 若要將此範例當做增益集來執行,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例。 開啟 Visual Basic 或 Visual C# 專案,再執行此範例。

[Visual Basic]

' Add-in code.
Imports VSLangProj
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)
    GenerateKeyPairs(applicationObject)
End Sub
Sub GenerateKeyPairs(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)
    ' Replace <file path> with an actual file path.
    aVSProject.GenerateKeyPairFiles("<file path>\MyKeyText.bin", "0")
End Sub

[C#]

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;
    GenerateKeyPair((DTE2)applicationObject);
}
public void GenerateKeyPair(DTE2 dte)
{
    Project aProject = null;
    VSProject2 aVSProject = null;
    aProject = applicationObject.Solution.Projects.Item(1);
    aVSProject = ((VSProject2)( 
applicationObject.Solution.Projects.Item(1).Object));
    // Replace the <file path> with an actual path.
    aVSProject.GenerateKeyPairFiles
("<file path>\\MyKeyText2.bin", "0");
}

.NET Framework 安全性

請參閱

參考

VSProject2 介面

GenerateKeyPairFiles 多載

VSLangProj80 命名空間