Partilhar via


VSProject2.Project Property

Definition

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

public:
 property EnvDTE::Project ^ Project { EnvDTE::Project ^ get(); };
public:
 property EnvDTE::Project ^ Project { EnvDTE::Project ^ get(); };
[System.Runtime.InteropServices.DispId(4)]
public EnvDTE.Project Project { [System.Runtime.InteropServices.DispId(4)] get; }
[<System.Runtime.InteropServices.DispId(4)>]
[<get: System.Runtime.InteropServices.DispId(4)>]
member this.Project : EnvDTE.Project
Public ReadOnly Property Project As Project

Property Value

A Project object.

Implements

Attributes

Examples

To run this example as an add-in, see How to: Compile and Run the Automation Object Model Code Examples. Open a Visual Basic or Visual C# project before running this example.

[Visual Basic]

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)  
    VSProjectSavedExample(applicationObject)  
End Sub  
Sub VSProjectSavedExample(ByVal dte As DTE2)  
    Dim aProject As Project  
    Dim aVSProject As VSProject2  
    aProject = applicationObject.Solution.Projects.Item(1)  
    aVSProject = CType(applicationObject.Solution.Projects.Item(1)._  
    Object, VSProject2)  
    IsProjectSaved(aVSProject)  
End Sub  
' Displays whether project has unsaved changes.  
Sub IsProjectSaved(ByVal aVSProject As VSProject2)  
    Dim theProject As EnvDTE.Project  
    theProject = aVSProject.Project  
    If (theProject.Saved) Then  
        MsgBox(theProject.Name & " is saved.")  
    Else  
        MsgBox(theProject.Name & " is not saved.")  
    End If  
End Sub  

[C#]

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;  
    VSProjectSavedExample((DTE2)applicationObject);  
}  

public void VSProjectSavedExample( DTE2 dte )   
{   
    Project aProject = null;   
    VSProject aVSProject = null;   
    aProject = applicationObject.Solution.Projects.Item( 1 );   
    aVSProject = ( ( VSProject )( applicationObject.Solution.Projects.  
Item( 1 ).Object ) );   
    IsProjectSaved( aVSProject );   
}   

//  Displays whether project has unsaved changes.  
public void IsProjectSaved( VSProject aVSProject )   
{   
    EnvDTE.Project theProject = null;   
    theProject = aVSProject.Project;   
    if ( ( theProject.Saved ) )   
    {   
        MessageBox.Show( theProject.Name + " is saved.");   
    }   
    else   
    {   
        MessageBox.Show( theProject.Name + " is not saved.");   
    }   
}  

Remarks

The VSProject2 object is a property of a generic Project object. The Project property provides access to the general extensibility Project object.

Applies to