ProjectItems.AddFromFile 方法

从安装在项目目录结构中的文件添加项目项。

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

语法

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

参数

  • FileName
    类型:System.String
    必选。要添加为项目项的项的文件名。

返回值

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

备注

如果要添加的文件已在项目中,则 AddFromFile 失败。

只要可以找到文件,FileName 就不需要包含完整路径。查找文件的方式取决于编程语言。例如,若要在 Visual Basic 和 Visual C# 中使用无路径文件,文件必须和项目在同一目录中。如果它们不是,则不会复制。Visual C++ 允许链接到该系统上任意位置的文件。

示例

Sub AddFromFileExample(app As DTE)
   ' 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 = app.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 10.0\Common7\IDE\ImportProjects\VB\ImportConsoleApplication.vbproj", "c:\temp2", "My New Project", True)
   projitems = proj.ProjectItems

   ' Add a project item from a file.
   projitems.AddFromFile("C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\NewFileItems\vbclass.vb")
End Sub

.NET Framework 安全性

请参见

参考

ProjectItems 接口

EnvDTE 命名空间

其他资源

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