共用方式為


ProjectItems.AddFromFileCopy 方法

複製原始程式檔,並將它加入專案。

命名空間:  EnvDTE
組件:  EnvDTE (在 EnvDTE.dll 中)

語法

'宣告
Function AddFromFileCopy ( _
    FilePath As String _
) As ProjectItem
ProjectItem AddFromFileCopy(
    string FilePath
)
ProjectItem^ AddFromFileCopy(
    String^ FilePath
)
abstract AddFromFileCopy : 
        FilePath:string -> ProjectItem 
function AddFromFileCopy(
    FilePath : String
) : ProjectItem

參數

  • FilePath
    型別:System.String
    必要項。要加入之專案項目的路徑和檔名。

傳回值

型別:EnvDTE.ProjectItem
ProjectItem 物件。

備註

AddFromFileCopy 會從已經安裝在專案目錄結構中的檔案加入專案項目,或視需要複製它的逐字規範,以便將其移動到專案目錄。 AddFromFileCopy 與 AddFromFile 不同,因為它不會新增連結,而且其不同於 AddFromTemplate,因為它不需要複製檔案或套用範本。

範例

此範例只適用於 Visual Studio .NET 2003。 如需詳細資訊,請參閱 Migrating Code that Creates Projects by Using Templates

Sub AddFromFileExample()
   ' 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 VB 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 a project item from a file.
   projitems.AddFromFileCopy("C:\temp\somefile.bas")
End Sub

.NET Framework 安全性

請參閱

參考

ProjectItems 介面

EnvDTE 命名空間

其他資源

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