Export (0) Print
Expand All

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)

[GuidAttribute("B1042570-25C6-424A-B58B-56FA83AA828A")] 
public interface VSProject2 : VSProject
/** @attribute GuidAttribute("B1042570-25C6-424A-B58B-56FA83AA828A") */ 
public interface VSProject2 extends VSProject
GuidAttribute("B1042570-25C6-424A-B58B-56FA83AA828A") 
public interface VSProject2 extends 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;
    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."); 
    } 
}
Show:
© 2014 Microsoft