共用方式為


ProjectItem.ContainingProject 屬性

取得裝載 ProjectItem 的專案。

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

語法

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

屬性值

型別:EnvDTE.Project
Project 物件。

範例

Sub ContainingProjectExample(ByVal dte As DTE2)

    ' Before running this example, open a code document from a project.
    Try
        ' Create a new namespace.
        Dim projItem As ProjectItem = dte.ActiveDocument.ProjectItem
        Dim cm As CodeModel = projItem.ContainingProject.CodeModel
        cm.AddNamespace("TestNamespace", projItem.Name)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
public void ContainingProjectExample(DTE2 dte)
{
    // Before running this example, open a code document from 
    // a project.
    try
    {
        // Create a new namespace.
        ProjectItem projItem = dte.ActiveDocument.ProjectItem;
        CodeModel cm = projItem.ContainingProject.CodeModel;
        cm.AddNamespace("TestNamespace", projItem.Name, -1);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 安全性

請參閱

參考

ProjectItem 介面

EnvDTE 命名空間

其他資源

HOW TO:編譯和執行 Automation 物件模型程式碼範例