共用方式為


VSProject2.Project 屬性

取得與 Visual Basic 或 Visual C# 專案關聯的泛型 Project 物件。

命名空間:  VSLangProj80
組件:  VSLangProj80 (在 VSLangProj80.dll 中)

語法

'宣告
ReadOnly Property Project As Project
Project Project { get; }
property Project^ Project {
    Project^ get ();
}
abstract Project : Project with get
function get Project () : Project

屬性值

類型:Project
Project 物件。

備註

VSProject2 物件是泛用 Project 物件的屬性。 Project 屬性可用來存取一般擴充 Project 物件的存取。

範例

若要將此範例當做增益集來執行,請參閱 如何:編譯和執行 Automation 物件模型程式碼範例。 開啟 Visual Basic 或 Visual C# 專案,再執行此範例。

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

.NET Framework 安全性

請參閱

參考

VSProject2 介面

VSLangProj80 命名空間

Project