Compartilhar via


Propriedade VSProject2.Project

Obtém a genérica Projecto objeto associado com o Visual Basic ou Visual C# projeto.

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

Sintaxe

'Declaração
ReadOnly Property Project As Project
Project Project { get; }
property Project^ Project {
    Project^ get ();
}
abstract Project : Project
function get Project () : Project

Valor de propriedade

Tipo: EnvDTE.Project
A Project objeto.

Comentários

O VSProject2 objeto é uma propriedade de um genérico Project objeto. O Project propriedade fornece acesso a extensibilidadegeralProjectobjeto.

Exemplos

Para executar este exemplo como um suplemento, consulte Como: compilar e executar os exemplos de código de modelo de objeto de automação.Abrir um Visual Basic ou Visual C#o projeto antes de executar este exemplo.

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

Segurança do .NET Framework

Consulte também

Referência

VSProject2 Interface

Sobrecargas Project

Namespace VSLangProj80

Project