更新:2007 年 11 月
从安装在项目目录结构中的文件添加项目项。
命名空间: EnvDTE
程序集: EnvDTE(在 EnvDTE.dll 中)
语法
声明
Function AddFromFile ( _
FileName As String _
) As ProjectItem
用法
Dim instance As ProjectItems
Dim FileName As String
Dim returnValue As ProjectItem
returnValue = instance.AddFromFile(FileName)
ProjectItem AddFromFile(
string FileName
)
ProjectItem^ AddFromFile(
[InAttribute] String^ FileName
)
function AddFromFile(
FileName : String
) : ProjectItem
参数
FileName
类型:System.String必需。要添加为项目项的项的文件名。
返回值
一个 ProjectItem 对象。
备注
如果要添加的文件已在项目中,则 AddFromFile 失败。
只要可以找到文件,FileName 就不需要包含完整路径。查找文件的方式取决于编程语言。例如,若要在 Visual Basic 和 Visual C# 中使用无路径文件,文件必须和项目在同一目录中。如果文件与项目不在同一目录中,则文件将被复制过来。Visual C++ 允许链接到系统中任何位置的文件。
示例
此示例仅适用于 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 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 a project item from a file.
projitems.AddFromFile("C:\temp\An Item.bas")
End Sub
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。