VSProject2.WebReferencesFolder 属性

获取表示项目的“Web 引用”文件夹的 ProjectItem 对象。 如果该文件夹不存在,此属性就会返回 Nothing(nullnull 引用(在 Visual Basic 中为 Nothing) 引用)。

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

语法

声明
ReadOnly Property WebReferencesFolder As ProjectItem
    Get
ProjectItem WebReferencesFolder { get; }
property ProjectItem^ WebReferencesFolder {
    ProjectItem^ get ();
}
abstract WebReferencesFolder : ProjectItem
function get WebReferencesFolder () : ProjectItem

属性值

类型:EnvDTE.ProjectItem
一个表示“Web 引用”文件夹的 ProjectItem 对象。

实现

VSProject.WebReferencesFolder

备注

可通过访问 WebReferencesFolderProjectItems 属性检索项目的 Web 引用。

一个项目最多包含一个“Web 引用”文件夹。 可使用 CreateWebReferencesFolder 方法创建该文件夹。 此外,当使用 CreateWebReferencesFolder 方法向项目添加第一个 Web 引用时,会自动创建该文件夹。

在 Visual Basic 或 Visual C# 项目中,WebReferencesFolder 项目项的 Kind 属性始终为 vsProjectItemKindPhysicalFolder,因为 Visual Basic 和 Visual C# 项目仅支持物理文件。

示例

如果还没有“Web 引用”文件夹,则此示例将创建一个“Web 引用”文件夹,并在消息框中显示一些文件夹属性。 若要将此示例作为外接程序运行,请参见如何:编译和运行自动化对象模型代码示例。 在运行此示例之前,请打开一个 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 安全性

请参见

参考

VSProject2 接口

WebReferencesFolder 重载

VSLangProj80 命名空间