VSProject2 Interface

Definition

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.

public interface class VSProject2 : VSLangProj::VSProject
public interface class VSProject2 : VSLangProj::VSProject
__interface VSProject2 : VSLangProj::VSProject
[System.Runtime.InteropServices.Guid("B1042570-25C6-424A-B58B-56FA83AA828A")]
[System.Runtime.InteropServices.TypeLibType(4160)]
public interface VSProject2 : VSLangProj.VSProject
[System.Runtime.InteropServices.Guid("B1042570-25C6-424A-B58B-56FA83AA828A")]
public interface VSProject2 : VSLangProj.VSProject
[<System.Runtime.InteropServices.Guid("B1042570-25C6-424A-B58B-56FA83AA828A")>]
[<System.Runtime.InteropServices.TypeLibType(4160)>]
type VSProject2 = interface
    interface VSProject
[<System.Runtime.InteropServices.Guid("B1042570-25C6-424A-B58B-56FA83AA828A")>]
type VSProject2 = interface
    interface VSProject
Public Interface VSProject2
Implements VSProject
Derived
Attributes
Implements

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.");   
    }   
}  

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.

Properties

BuildManager

Gets the BuildManager object of the VSProject.

DTE

Gets the top-level extensibility object.

Events

Gets a VSProjectEvents object that allows you to respond to events of the Imports, References, and BuildManager objects.

Events2

Gets a VSProjectEvents2 object that allows you to respond to events of the Imports, References, BuildManager, and VSLangProjWebReferencesEvents objects.

Imports

Gets the Imports object associated with the project. For C# projects, the Imports property is set to Nothing (a null reference).

Project

Gets the generic Project object associated with the Visual Basic or Visual C# project.

PublishManager

Gets a PublishManager object to allow click once publishing.

References

Gets the References collection for the project.

TemplatePath

This property is deprecated in Microsoft Visual Studio 2005. Use GetProjectItemTemplate(String, String) instead.

WebReferencesFolder

Gets the ProjectItem object representing the Web References folder of the project. If the folder does not exist, this property returns Nothing (a null reference).

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.

Methods

AddWebReference(String)

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.

CopyProject(String, String, prjCopyProjectOption, String, String)

Copies some or all of a Web project to a new location.

CreateWebReferencesFolder()

Creates the Web References folder for the project.

Exec(prjExecCommand, Int32, Object, Object)

Microsoft Internal Use Only.

GenerateKeyPairFiles(String, String)

Generates a public/private key file used to form a strong name for the assembly.

GetUniqueFilename(Object, String, String)

Generates a unique file name within the project. it is used for naming new project items.

Refresh()

Refreshes the appearance of the project in Solution Explorer and refreshes the references.

Applies to