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 对象的访问。

示例

若要将此示例作为外接程序运行,请参见如何:编译和运行自动化对象模型代码示例。 在运行此示例之前,请打开一个 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