VSProject2.WebReferencesFolder 屬性
取得代表專案 Web 參考資料夾的 ProjectItem 物件。如果資料夾不存在,這個屬性會傳回 Nothing (nullNull 參照 (即 Visual Basic 中的 Nothing) 參考)。
命名空間: VSLangProj80
組件: VSLangProj80 (在 VSLangProj80.dll 中)
語法
'宣告
ReadOnly Property WebReferencesFolder As ProjectItem
ProjectItem WebReferencesFolder { get; }
property ProjectItem^ WebReferencesFolder {
ProjectItem^ get ();
}
abstract WebReferencesFolder : ProjectItem
function get WebReferencesFolder () : ProjectItem
屬性值
型別:EnvDTE.ProjectItem
代表 Web 參考資料夾的 ProjectItem 物件。
備註
專案的 Web 參考可經由存取 WebReferencesFolder 的 ProjectItems 屬性來擷取。
一個專案最多只能包含一個 Web 參考資料夾。這個資料夾可使用 CreateWebReferencesFolder 方法來建立。除此之外,當使用 CreateWebReferencesFolder 方法將第一個 Web 參考加入至專案時,就會自動建立這個資料夾。
在 Visual Basic 或 Visual C# 專案中,WebReferencesFolder 專案項目的 Kind 屬性永遠為 vsProjectItemKindPhysicalFolder,因為 Visual Basic 和 Visual C# 專案僅支援實體檔案。
範例
如果 Web 參考資料夾不存在,此範例便會建立一個,並且會在訊息方塊中顯示部分資料夾屬性。若要將此範例當做增益集來執行,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例。開啟 Visual Basic 或 Visual C# 專案,再執行此範例。
[Visual Basic]
' Add-in code.
' This example creates a Web references folder, if it does not
' already exist, and displays some of the folder properties.
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)
WebReferencesFolderExample(applicationObject)
End Sub
Sub WebReferencesFolderExample(ByVal dte As DTE2)
' This example assumes that the first project in the
' solution is a Visual Basic or C# project.
Dim aVSProject As VSProject2 = _
CType(applicationObject.Solution.Projects.Item(1)._
Object, VSProject2)
' Add a new folder if it does not already exist.
If (aVSProject.WebReferencesFolder Is Nothing) Then
Dim newFolder As ProjectItem
newFolder = aVSProject.CreateWebReferencesFolder()
End If
' Display the name of the Web references folder.
Dim theFolder As ProjectItem = aVSProject.WebReferencesFolder
MsgBox("The name of the WebReferences folder is " _
& theFolder.Name & ".")
' All Visual Basic and C# Web references folders are physical.
If (theFolder.Kind = _
EnvDTE.Constants.vsProjectItemKindPhysicalFolder) Then
MsgBox(theFolder.Name & " is a physical folder.")
End If
MsgBox("There are " & theFolder.ProjectItems.Count.ToString() & _
" Web references.")
End Sub
[C#]
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;
WebReferencesFolderExample((DTE2)applicationObject);
}
public void WebReferencesFolderExample( DTE2 dte )
{
// This example assumes that the first project in the
// solution is a Visual Basic or C# project.
VSProject2 aVSProject = ( ( VSProject2 )
(applicationObject.Solution.Projects.Item( 1 ).Object ) );
// Add a new folder if it does not already exist.
if ( ( aVSProject.WebReferencesFolder == null ) )
{
ProjectItem newFolder = null;
newFolder = aVSProject.CreateWebReferencesFolder();
}
// Display the name of the Web references folder.
ProjectItem theFolder = aVSProject.WebReferencesFolder;
MessageBox.Show( "The name of the WebReferences folder is "
+ theFolder.Name + ".");
// All Visual Basic and C# Web references folders are physical.
if ( ( theFolder.Kind ==
EnvDTE.Constants.vsProjectItemKindPhysicalFolder ) )
{
MessageBox.Show( theFolder.Name + " is a physical folder.");
}
MessageBox.Show( "There are " +
theFolder.ProjectItems.Count.ToString() + " Web references.");
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。