ProjectItems.AddFromDirectory 方法

将一个或多个 ProjectItem 对象从目录添加到 ProjectItems 集合。

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

语法

声明
Function AddFromDirectory ( _
    Directory As String _
) As ProjectItem
ProjectItem AddFromDirectory(
    string Directory
)
ProjectItem^ AddFromDirectory(
    [InAttribute] String^ Directory
)
abstract AddFromDirectory : 
        Directory:string -> ProjectItem
function AddFromDirectory(
    Directory : String
) : ProjectItem

参数

  • Directory
    类型:String

    必选。 要添加的项目项所来自的目录。

返回值

类型:EnvDTE.ProjectItem
一个 ProjectItem 对象。

备注

AddFromDirectory 在给定目录及其子目录中逐个执行,将其所有项自动添加到项目,从而使您不用多次执行添加项操作。

示例

此示例仅适用于 Visual Studio .NET 2003。 有关详细信息,请参阅Migrating Code that Creates Projects by Using Templates

Sub AddFromDirectoryExample()
   ' This function creates a solution and adds a Visual Basic Console
   ' project to it. 
   Dim soln As Solution
   Dim proj As Project
   Dim projitems As ProjectItems

   ' Create a reference to the solution.
   soln = DTE.Solution

   ' Create a new solution.
   soln.Create("c:\temp2", "MyNewSolution")

   ' Create a new Visual Basic Console application project.
   ' Adjust the save path as needed.
   proj = soln.AddFromTemplate("C:\Program Files\Microsoft Visual Studio .NET\Vb7\VBWizards\ConsoleApplication\Templates\1033\ConsoleApplication.vbproj", "c:\temp2", "My New Project", True)
   projitems = proj.ProjectItems

   ' Add all of the items in the specified directory (and subdirectories) 
   ' to the project.
   projitems.AddFromDirectory("C:\Program Files\Microsoft Visual Studio .NET\Vb7\VBWizards\ConsoleApplication\Templates\1033")
End Sub

.NET Framework 安全性

请参阅

参考

ProjectItems 接口

EnvDTE 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例