Condividi tramite


VSProject2.GenerateKeyPairFiles(String, String) Method

Definition

Generates a public/private key file used to form a strong name for the assembly.

void GenerateKeyPairFiles(std::wstring const & strPublicPrivateFile, std::wstring const & strPublicOnlyFile = "0");
[System.Runtime.InteropServices.DispId(15)]
public void GenerateKeyPairFiles (string strPublicPrivateFile, string strPublicOnlyFile = "0");
[<System.Runtime.InteropServices.DispId(15)>]
abstract member GenerateKeyPairFiles : string * string -> unit
Public Sub GenerateKeyPairFiles (strPublicPrivateFile As String, Optional strPublicOnlyFile As String = "0")

Parameters

strPublicPrivateFile
String

The name of the file to be generated.

strPublicOnlyFile
String

If true, only the public key is generated.

Implements

Attributes

Examples

This example generates a binary file that contains the key pair. To view the generated file, use the Sn.exe (Strong Name Tool). To run this example as an add-in, see How to: Compile and Run the Automation Object Model Code Examples. Open a Visual Basic or Visual C# project before running this example.

[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");  
}  

Remarks

A strong name consists of the assembly's identity — its simple text name, version number, and culture information (if provided) — plus a public key and a digital signature. The public/private key pair, used to create the digital signature, may be stored in a file or in a container in the Cryptographic Service Provider. The Sn.exe (Strong Name Tool) creates the file or container. The container name is specified by the user when running the tool, and that same name is used in this property. For more information, see Strong-Named Assemblies.

A cryptographic service provider is an independent software module that performs cryptography algorithms for authentication, encoding, and encryption. For more information, see Cryptographic Services.

Applies to