共用方式為


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
    型別:System.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 命名空間

其他資源

HOW TO:編譯和執行 Automation 物件模型程式碼範例