ProjectItems.AddFromFileCopy 方法

更新:2007 年 11 月

复制源文件并将其添加到项目中。

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

语法

声明
Function AddFromFileCopy ( _
    FilePath As String _
) As ProjectItem
用法
Dim instance As ProjectItems
Dim FilePath As String
Dim returnValue As ProjectItem

returnValue = instance.AddFromFileCopy(FilePath)
ProjectItem AddFromFileCopy(
    string FilePath
)
ProjectItem^ AddFromFileCopy(
    String^ FilePath
)
function AddFromFileCopy(
    FilePath : String
) : ProjectItem

参数

  • FilePath
    类型:System.String

    必需。待添加项目项的路径及其文件名。

返回值

类型:EnvDTE.ProjectItem

一个 ProjectItem 对象。

备注

AddFromFileCopy 从已安装到项目目录结构中的文件添加项目项,如有必要,还可以对其进行逐字复制,以将其移动到项目目录中。AddFromFileCopy 与 AddFromFile 不同,因为前者不添加链接,而且前者与 AddFromTemplate 也不同,差异在于它不必复制文件或应用模板。

示例

此示例仅适用于 Visual Studio .NET 2003。有关更多信息,请参见如何:迁移使用模板创建项目的代码

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

权限

另请参见

参考

ProjectItems 接口

ProjectItems 成员

EnvDTE 命名空间

其他资源

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