共用方式為


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 的名稱 (如果有的話)。若要將此範例當做增益集來執行,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例。開啟 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 命名空間