ItemOperations.AddNewItem(String, String) 方法

定义

将新项添加到当前项目。Adds a new item to the current project.

EnvDTE::ProjectItem AddNewItem(std::wstring const & Item = "General\Text File", std::wstring const & Name = "");
[System.Runtime.InteropServices.DispId(7)]
public EnvDTE.ProjectItem AddNewItem (string Item = "General\Text File", string Name = "");
[<System.Runtime.InteropServices.DispId(7)>]
abstract member AddNewItem : string * string -> EnvDTE.ProjectItem
Public Function AddNewItem (Optional Item As String = "General\Text File", Optional Name As String = "") As ProjectItem

参数

Item
String

可选。Optional. 项的虚拟路径基于 UI 资源字符串 (在下面的 "备注" 部分中定义的) 或偶尔显示在 "类别templatename" 格式的 "新建文件" 对话框的内容中 \ The virtual path to the item based on either the UI resource string (defined in the Remarks section below) or occasionally as displayed in the contents of the New File dialog box in "category\templatename" format. 类别 来自对话框的左窗格,并从右窗格 templatenameCategory comes from the left pane of the dialog box and templatename from the right pane. 例如,若要向项目中添加新的 HTML 文件 Visual BasicVisual Basic ,请使用 "General\HTML 页"。For example, to add a new HTML file to a Visual BasicVisual Basic project, you would use "General\HTML Page." 有关详细信息,请参阅备注部分。See the Remarks section for more information.

Name
String

可选。Optional. 将项添加到项目时项所用的显示名称。The display name to use for the item when it is added to a project.

返回

ProjectItem

ProjectItem 对象。A ProjectItem object.

属性

示例

Sub AddNewItemExample()  
   Dim ItemOp As ItemOperations  
   ItemOp = DTE.ItemOperations  
   ItemOp.AddNewItem("General\Text File", "A new text file")  
End Sub  

注解

AddNewItem 对 " 新文件 " 对话框建模。AddNewItem models the New File dialog box. 此对话框的内容因项目类型而异。The contents of this dialog box vary depending on the type of project. 可以通过两种方法来确定要放置在参数中的值 Item :在 " 新建文件 " 对话框中查找值,或在相应的 UI 资源文件中查找值。There are two ways to determine the values to place in the Item parameter: look up the values in the New File dialog box, or look up the values in the appropriate UI resource file.

若要使用第一种方法向某些项目添加项,请在 " 新建文件 " 对话框中查看项目的可用项。To add items to a some projects by using the first method, look at the items available for the project in the New File dialog box. " 新建文件 " 对话框包含两个窗格: " 类别 " 和 " 模板"。The New File dialog box has two panes: Categories and Templates. Item方法的参数 AddNewItemThe Item parameter of the AddNewItem method is

格式为 " category \ templatename "。in "category\templatename" format. Category 通常来自对话框的左窗格 (类别) 并 templatename 从右窗格 (模板) 。Category usually comes from the left pane of the dialog box (Categories) and templatename from the right pane (Templates). 例如,若要向项目中添加新的 HTML 文件 Visual BasicVisual Basic ,请使用 "General\HTML 页"。For example, to add a new HTML file to a Visual BasicVisual Basic project, you would use "General\HTML Page." 但由于语言差异,在 " 新建文件 " 对话框中不会始终准确反映此值的确切值。Because of language differences, however, the exact values for this are not always reflected precisely in the New File dialog box.

获取参数的准确值的更一致、更可靠的方法 Item 是在 UI 资源文件中查找每种编程语言的必需字符串。A more consistent and reliable method for getting the exact values for the Item parameter is to look up the necessary string in the UI resource file for each programming language. 然后,将此值与要添加的项的名称一起使用,在 " 新建文件 " 和 " 添加新项 " 对话框中显示。You then use this value along with the name of the item you want to add, as it displays in the New File and Add New Item dialog boxes. 例如,若要将新的 Visual BasicVisual Basic 类文件添加到项目中,请使用 AddNewItem("Visual Basic Items\Class", "test.vb")For example, to add a new Visual BasicVisual Basic class file to your project, you would use AddNewItem("Visual Basic Items\Class", "test.vb"). 若要将新的 Visual C#Visual C# 类文件添加到项目中,请使用 AddNewItem("Visual C# Project Items\Class", test.cs");To add a new Visual C#Visual C# class file to your project, you would use AddNewItem("Visual C# Project Items\Class", test.cs");.

字符串 "Visual Basic 项" (以及其他语言项) 可通过以下方式找到:The string "Visual Basic Items" (as well as other language items) is found the following way:

  • 对于 Visual BasicVisual Basic 文件,请打开以下注册表项: HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\8.0\Projects\ {F184B08F-C81C-45f6-A57F-5ABD9991F28F} \AdditemTemplates\TemplateDirs \ {164B10B9-B200-11D0-8C61-00A0C91E29D5} /1。For the Visual BasicVisual Basic file, open the following registry key: HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\8.0\Projects\{F184B08F-C81C-45f6-A57F-5ABD9991F28F}\AdditemTemplates\TemplateDirs\{164B10B9-B200-11D0-8C61-00A0C91E29D5}\ /1. 默认值为 #3082。Its default value is #3082.

  • 使用资源编辑器打开 msvbprjui.dll 中的文件 Visual StudioVisual StudioOpen the file msvbprjui.dll in Visual StudioVisual Studio using the Resource editor. 为此,请通过选择 "文件 ..." 浏览到该文件。To do this, browse to the file by selecting File… 在 "打开" 菜单上的 "文件" 菜单上,打开文件。on the Open menu, which is on the File menu, and then open the file. 打开 "字符串表" 节点,查看 "资源 ID 3082",将其设置为 "Visual Basic 项"。Open the String Table node and look at resource ID 3082, it is set to "Visual Basic Items." 这是放置在调用中的字符串 AddNewItemThis is the string you put in the AddNewItem call. 同样的过程适用于 Visual C#Visual C#Visual C++Visual C++Visual C#Visual C# 项目系统,但要使用的文件名和资源 id 不同。The same procedure applies to the Visual C#Visual C# , Visual C++Visual C++, and Visual C#Visual C# project systems except the file names and resource IDs to use are different.

下面是 UI 资源文件的资源 Id 和位置表:Following is a table of resource IDs and locations for the UI resource files:

编程语言Programming Language UI 文件名UI File Name 类的资源 IDResource ID for Class
Visual BasicVisual Basic ..\Program Files\Microsoft Visual Studio 8\VB\Bin\1033\msvbprojUI.dll…\Program Files\Microsoft Visual Studio 8\VB\Bin\1033\msvbprojUI.dll 30823082
Visual C#Visual C# . ..\Program Files\Microsoft Visual Studio 8 \ v i # \VCSPackages\1033\csprjui.dll…\Program Files\Microsoft Visual Studio 8\VC#\VCSPackages\1033\csprjui.dll 23462346
Visual C++Visual C++ ..\Program Files\Microsoft Visual Studio 8\VC\vcpackages\1033\VCProjectUI.dll…\Program Files\Microsoft Visual Studio 8\VC\vcpackages\1033\VCProjectUI.dll 1000710007

适用于