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 命名空间

其他资源

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