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.

public interface class VSProject2 : VSLangProj::VSProject
public interface class VSProject2 : VSLangProj::VSProject
__interface VSProject2 : VSLangProj::VSProject
public interface VSProject2 : VSLangProj.VSProject
type VSProject2 = interface
    interface VSProject
Public Interface VSProject2
Implements VSProject


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


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.



Gets the BuildManager object of the VSProject.


Gets the top-level extensibility object.


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


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


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


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


Gets a PublishManager object to allow click once publishing.


Gets the References collection for the project.


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


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


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.



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.


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.


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

Applies to