Reference3.SourceProject 属性

如果引用是一个项目,则获取 Project 对象。否则,它将返回 Nothing(null 对象)。

命名空间:  VSLangProj80
程序集:  VSLangProj80(在 VSLangProj80.dll 中)

语法

声明
ReadOnly Property SourceProject As Project
Project SourceProject { get; }
property Project^ SourceProject {
    Project^ get ();
}
abstract SourceProject : Project
function get SourceProject () : Project

属性值

类型:EnvDTE.Project
返回 Project 对象。

备注

为了让某个项目使用由第二个项目生成的对象,第一个项目必须包含对第二个项目的引用。在这种情况下,SourceProject 属性可返回第二个项目的 Project 对象。

示例

此示例循环访问所有引用并显示 SourceProject 的名称(如果存在)。若要将此示例作为外接程序运行,请参见如何:编译和运行自动化对象模型代码示例。在运行此示例之前,请打开一个 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)
    DisplaySourceProjectName(applicationObject)
End Sub
Public Sub DisplaySourceProjectName(ByVal dte As DTE2)
    ' The first project is a Visual Basic or C# project.
    Dim vsProject As VSProject2 =_
    CType(applicationObject.Solution.Projects.Item(1).Object, _
    VSProject2)
    Dim aRef As Reference3
    Dim refStr As String
    refStr = ""
    Dim project As EnvDTE.Project
    For Each aRef In vsProject.References
        project = aRef.SourceProject
        If project Is Nothing Then
            refStr += (aRef.Name & " has no source project." & vbCr _
            & vbCr)
        Else
            refStr += (aRef.Name & " has a source project named " _
            & project.Name & vbCr & vbCr)
        End If
    Next
    MsgBox(refStr)
End Sub
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;
    DisplaySourceProjectName(((DTE2)applicationObject));
}
public void DisplaySourceProjectName(DTE2 dte)
{
    // The first project is a Visual Basic or C# project.
    VSProject2 aProject = 
((VSProject2)(applicationObject.Solution.Projects.Item(1).Object));
    Reference3 aRef = null;
    string refStr = null;
    refStr = "";
    EnvDTE.Project project = null;
    foreach (VSLangProj80.Reference3 temp in aProject.References)
    {
        aRef = temp; 
        project = aRef.SourceProject;
        if (project == null)
        {
            refStr += (aRef.Name + " has no source project." + "\n" 
+ "\n");
        }
        else
        {
            refStr += (aRef.Name + " has a source project named " 
+ project.Name + "\n" + "\n");
        }
    }
    MessageBox.Show(refStr);
}

.NET Framework 安全性

请参见

参考

Reference3 接口

SourceProject 重载

VSLangProj80 命名空间