Поделиться через


VSProject2.GenerateKeyPairFiles Method

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

Namespace:  VSLangProj80
Assembly:  VSLangProj80 (in VSLangProj80.dll)

Syntax

'Declaration
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
)

Parameters

  • strPublicPrivateFile
    Type: System.String

    The name of the file to be generated.

  • strPublicOnlyFile
    Type: System.String

    If true, only the public key is generated.

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.

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

.NET Framework Security

See Also

Reference

VSProject2 Interface

VSLangProj80 Namespace