We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

VSProject2 Interface

Contains the information specific to a Visual Basic, Visual C#, or Visual J# project. The Object object returns it when the project is a Visual Basic, Visual C#, or Visual J# project.

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

public interface VSProject2 : VSProject

Project is a core extensibility object that can contain information about projects of any language. The Object property of the Project object returns an object whose type depends on the project language used. In the case of Visual Basic, Visual C#, and Visual J#, that object is a VSProject2 object.

The Object property returns an Object data type. The data object returned by the Object property may then be explicitly converted to VSProject2. The example below demonstrates this conversion using the CType function. The PrjKind is used to test for the project's type before the conversion.

To run this example as an add-in, see How to: Compile and Run the Automation Object Model Code Examples.

To determine if a Visual Basic or a Visual C# project is a smart device project, use the prjKindSDEVBProject and prjKindSDECSharpProject.

// To use Messabox.Show, a reference to Windows.Forms is required.
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;

public void VSProject2Example(DTE2 dte)
    Project aProject = null; 
    VSProject aVSProject2 = null; 
    aProject = applicationObject.Solution.Projects.Item( 1 ); 
    MessageBox.Show( aProject.Kind + aProject.Name); 
    if ( ( aProject.Kind == PrjKind.prjKindVBProject ) |
 ( aProject.Kind == PrjKind.prjKindCSharpProject ) |
 ( aProject.Kind == PrjKind2.prjKindVJSharpProject ) ) 
        aVSProject2 = ( ( VSProject )
(applicationObject.Solution.Projects.Item( 1 ).Object ) ); 
        MessageBox.Show( aVSProject2.Project.FullName); 
        MessageBox.Show( "The first project is not a Visual Basic,
 C# or J# project.");