VSProject2.References 屬性
取得此專案的 References 集合。
命名空間: VSLangProj80
組件: VSLangProj80 (在 VSLangProj80.dll 中)
語法
'宣告
ReadOnly Property References As References
Get
References References { get; }
property References^ References {
References^ get ();
}
abstract References : References
function get References () : References
屬性值
型別:VSLangProj.References
含有 Reference 物件的 References 集合,其中每一個物件都代表一個參考。
實作
備註
若要針對外部元件撰寫程式碼,您的專案必須先包含這個元件的參考。 參考可建成三種元件:.NET 組件 (Assembly)、COM Automation 伺服程式和控制項及其他在相同方案內公開元件的專案。
範例
若要將此範例當做增益集來執行,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例。 這個範例假設方案中的第一個專案是 Visual Basic 或 Visual C# 專案。
[Visual Basic]
' Add-in.
' Assuming that the first project in the solution is a Visual Basic
' or C# application, this routine lists the references
' in the project.
Imports VSLangProj
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)
ListReferences(applicationObject)
End Sub
Sub ListReferences(ByVal dte As DTE2)
' Retrieve the VSProject2 object.
Dim theVSProject As VSProject2 = _
CType(applicationObject.Solution.Projects.Item(1).Object, _
VSProject2)
' Retrieve the references collection.
Dim refs As References = theVSProject.References
' Create a string list of the reference names.
Dim refList As String = ""
Dim aRef As Reference3
For Each aRef In refs
refList &= aRef.Identity & ControlChars.CrLf
Next
MsgBox(refList)
End Sub
[C#]
// Add-in.
// Assuming that the first project in the solution is a Visual Basic
// or C# application, this routine lists the references
// in the project.
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;
ListReferences((DTE2)applicationObject);
}
public void ListReferences( DTE2 dte )
{
// Retrieve the VSProject2 object.
VSProject2 theVSProject = ( ( VSProject2 )
(applicationObject.Solution.Projects.Item( 1 ).Object ) );
// Retrieve the references collection.
References refs = theVSProject.References;
// Create a string list of the reference names.
string refList = "";
Reference3 aRef = null;
foreach ( VSLangProj80.Reference3 temp in refs )
{
aRef = temp;
refList += aRef.Identity + "\n";
}
MessageBox.Show( refList);
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。