Reference3.ContainingProject 属性

定义

获取 Project 包含引用的。

public:
 property EnvDTE::Project ^ ContainingProject { EnvDTE::Project ^ get(); };
public:
 property EnvDTE::Project ^ ContainingProject { EnvDTE::Project ^ get(); };
[System.Runtime.InteropServices.DispId(3)]
public EnvDTE.Project ContainingProject { [System.Runtime.InteropServices.DispId(3)] get; }
[<System.Runtime.InteropServices.DispId(3)>]
[<get: System.Runtime.InteropServices.DispId(3)>]
member this.ContainingProject : EnvDTE.Project
Public ReadOnly Property ContainingProject As Project

属性值

Project

Project包含引用的对象。

实现

属性

示例

此示例将显示所有引用的包含项目,并在打开或项目中单独显示每个引用的项目 Visual Basic Visual C# 。 若要将此示例作为外接程序运行,请参阅 如何:编译和运行自动化对象模型代码示例

Imports VSLangProj  
Imports VSLangProj2  
Imports VSLangProj80  
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)  
    TestGetProjectName(applicationObject)  
End Sub  
Sub TestGetProjectName(ByVal dte As DTE2)  
    ' First project is a Visual Basic or C# project.  
    Dim theVSProject As VSProject2 = _  
    CType(applicationObject.Solution.Projects.Item(1)._  
    Object, VSProject2)  
    Dim refs As References = theVSProject.References  
    MsgBox("The containing project for all references is : " _  
    & GetProjectName(refs))  
    Dim aRef As Reference3  
    Dim refStr As String  
    refStr = ""  
    For Each aRef In theVSProject.References  
        refStr &= (aRef.Name & "'s containing project is: " _  
        & aRef.ContainingProject.Name & vbCr)  
    Next  
    MsgBox("The containing project for each reference in the project:" _  
    & vbCr & vbCr & refStr & vbCr)  
End Sub  
Private Function GetProjectName(ByVal refs As References) _  
    As String  
    Return refs.ContainingProject.Name  
End Function  
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;  
    TestGetProjectName(((DTE2)applicationObject));  
}  
public void TestGetProjectName(DTE2 dte)  
{  
    // First project is a Visual Basic or C# project.  
    VSProject2 theVSProject =   
((VSProject2)(applicationObject.Solution.Projects.Item(1).Object));  
    References refs = theVSProject.References;  
    MessageBox.Show("The containing project for all references is : "   
+ GetProjectName(refs));  
    Reference aRef = null;  
    string refStr = null;  
    refStr = "";  
    foreach (VSLangProj80.Reference3 temp in theVSProject.References)  
    {  
        aRef = temp;  
        refStr += (aRef.Name + "'s containing project is: "   
+ aRef.ContainingProject.Name + "\n");  
    }  
    MessageBox.Show("The containing project for each reference in   
the project:" + "\n" + "\n" + refStr + "\n");  
}  

private string GetProjectName(References refs)  
{  
    return refs.ContainingProject.Name;  
}  

注解

使用此属性可以检索 Project 包含引用的对象。

适用于