Share via


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)

Syntax

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

The VSProject2 type exposes the following members.

Properties

  Name Description
Public property BuildManager Gets the BuildManager object of the VSProject.
Public property DTE Gets the top-level extensibility object.
Public property Events Gets a VSProjectEvents object that allows you to respond to events of the Imports, References, and BuildManager objects.
Public property Events2 Gets a VSProjectEvents2 object that allows you to respond to events of the Imports, References, BuildManager, and VSLangProjWebReferencesEvents objects.
Public property Imports Gets the Imports object associated with the project. For C# projects, the Imports property is set to Nothing (a nulla null reference (Nothing in Visual Basic) reference).
Public property Project Gets the generic Project object associated with the Visual Basic or Visual C# project.
Public property PublishManager Gets a PublishManager object to allow click once publishing.
Public property References Gets the References collection for the project.
Public property TemplatePath This property is deprecated in Microsoft Visual Studio 2005. Use GetProjectItemTemplate instead.
Public property WebReferencesFolder Gets the ProjectItem object representing the Web References folder of the project. If the folder does not exist, this property returns Nothing (a nulla null reference (Nothing in Visual Basic) reference).
Public property WorkOffline Indicates 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.

Top

Methods

  Name Description
Public method AddWebReference Adds 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 method CopyProject Copies some or all of a Web project to a new location.
Public method CreateWebReferencesFolder Creates the Web References folder for the project.
Public method Exec Infrastructure. Microsoft Internal Use Only.
Public method GenerateKeyPairFiles Generates a public/private key file used to form a strong name for the assembly.
Public method GetUniqueFilename Generates a unique file name within the project. it is used for naming new project items.
Public method Refresh Refreshes the appearance of the project in Solution Explorer and refreshes the references.

Top

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 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.

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.

[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 _
 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) Then
        aVSProject2 = CType(applicationObject.Solution.Projects.Item(1).Object, _
        VSProject2)
        MsgBox(aVSProject2.Project.FullName)
    Else
        MsgBox("The first project is not a Visual Basic or C# _
        project.")
    End If
End Sub

[C#]

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

See Also

Reference

VSLangProj80 Namespace

VSProject