Partager via


VSProject2.Project, propriété

Obtient l'objet Project générique associé au projet Visual Basic ou Visual C#.

Espace de noms :  VSLangProj80
Assembly :  VSLangProj80 (dans VSLangProj80.dll)

Syntaxe

'Déclaration
ReadOnly Property Project As Project
Project Project { get; }
property Project^ Project {
    Project^ get ();
}
abstract Project : Project
function get Project () : Project

Valeur de propriété

Type : EnvDTE.Project
Objet Project.

Notes

L'objet VSProject2 est une propriété d'un objet Project générique.La propriété Project offre un accès à l'objet Project d'extensibilité générale.

Exemples

Pour exécuter cet exemple comme un complément, consultez Comment : compiler et exécuter les exemples de code du modèle objet Automation.Ouvrez un projet Visual Basic ou Visual C# avant d'exécuter cet exemple.

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

Sécurité .NET Framework

Voir aussi

Référence

VSProject2 Interface

Project, surcharge

VSLangProj80, espace de noms

Project