VSProject2 Interface

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

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

public interface VSProject2 : VSProject

The VSProject2 type exposes the following members.

Public propertyBuildManagerGets the BuildManager object of the VSProject.
Public propertyDTEGets the top-level extensibility object.
Public propertyEventsGets a VSProjectEvents object that allows you to respond to events of the Imports, References, and BuildManager objects.
Public propertyEvents2Gets a VSProjectEvents2 object that allows you to respond to events of the Imports, References, BuildManager, and VSLangProjWebReferencesEvents objects.
Public propertyImportsGets the Imports object associated with the project. For C# projects, the Imports property is set to Nothing (a null reference).
Public propertyProjectGets the generic Project object associated with the Visual Basic or Visual C# project.
Public propertyPublishManagerGets a PublishManager object to allow click once publishing.
Public propertyReferencesGets the References collection for the project.
Public propertyTemplatePathThis property is deprecated in Microsoft Visual Studio 2005. Use GetProjectItemTemplate instead.
Public propertyWebReferencesFolderGets the ProjectItem object representing the Web References folder of the project. If the folder does not exist, this property returns Nothing (a null reference).
Public propertyWorkOfflineIndicates whether a Web project is working online or offline. When it is working offline, development continues on an offline store of project files, so that the project files on the server are not changed.

Public methodAddWebReferenceAdds a reference to a Web Service to the project. A new Web Service reference subfolder is added to the Web References folder of the project. This new folder contains several other project items related to the Web Service. The method returns the ProjectItem object associated with the new Web Service folder.
Public methodCopyProjectCopies some or all of a Web project to a new location.
Public methodCreateWebReferencesFolderCreates the Web References folder for the project.
Public methodExecInfrastructure. Microsoft Internal Use Only.
Public methodGenerateKeyPairFilesGenerates a public/private key file used to form a strong name for the assembly.
Public methodGetUniqueFilenameGenerates a unique file name within the project. it is used for naming new project items.
Public methodRefreshRefreshes the appearance of the project in Solution Explorer and refreshes the references.

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 and Visual C#, 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.

[Visual Basic]

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 _
    applicationObject = CType(application, DTE2)
    addInInstance = CType(addInInst, AddIn)
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) Then
        aVSProject2 = CType(applicationObject.Solution.Projects.Item(1).Object, _
        MsgBox("The first project is not a Visual Basic or C# _
    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;

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 ) ) 
        aVSProject2 = ( ( VSProject )
(applicationObject.Solution.Projects.Item( 1 ).Object ) ); 
        MessageBox.Show( aVSProject2.Project.FullName); 
        MessageBox.Show( "The first project is not a Visual Basic or C# project.");