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)

Syntax

'Declaration
<GuidAttribute("B1042570-25C6-424A-B58B-56FA83AA828A")> _
Public Interface VSProject2 _
    Inherits VSProject
'Usage
Dim instance As VSProject2
[GuidAttribute("B1042570-25C6-424A-B58B-56FA83AA828A")]
public interface VSProject2 : VSProject
[GuidAttribute(L"B1042570-25C6-424A-B58B-56FA83AA828A")]
public interface class VSProject2 : VSProject
public interface VSProject2 extends VSProject

Remarks

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.

Examples

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.

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)
    VSProject2Example(applicationObject)
End Sub

 Sub VSProject2Example(ByVal dte As DTE2)
    Dim aProject As Project
    Dim aVSProject2 As VSProject2

    aProject = applicationObject.Solution.Projects.Item(1)
    MsgBox(aProject.Kind & aProject.Name)
    If (aProject.Kind = PrjKind.prjKindVBProject) Or_
    (aProject.Kind = PrjKind.prjKindCSharpProject) Or_
    (aProject.Kind = PrjKind2.prjKindVJSharpProject) Then
        aVSProject2 = CType(applicationObject.Solution.Projects.Item(1).Object, _
        VSProject2)
        MsgBox(aVSProject2.Project.FullName)
    Else
        MsgBox("The first project is not a Visual Basic, C# _
        or J# project.")
    End If
End Sub
// 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;
    VSProject2Example((DTE2)applicationObject);
}

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); 
    } 
    else 
    { 
        MessageBox.Show( "The first project is not a Visual Basic,
 C# or J# project."); 
    } 
}

See Also

Reference

VSProject2 Members

VSLangProj80 Namespace

VSProject