简体   繁体   English

将ProjectItem移到VS2012中的自定义向导中用于项目模板的物理目录中

[英]Move ProjectItem to physical directory in custom wizard for Item Template in VS2012

In Visual Studio 2012 (or below, preferably), is it possible to direct a newly created item to a particular folder in the filesystem instead of it going directly to the project root with a project item template? 在Visual Studio 2012(或以下版本,优选)中,是否可以将新创建​​的项目直接定向到文件系统中的特定文件夹,而不是使用项目项目模板直接将其创建到项目根目录?

The ProjectItem.Save() and SaveAs() methods throw an unimplemented exception. ProjectItem.Save()SaveAs()方法将引发未实现的异常。

The short answer is no: you can't direct a file to a subfolder of your project using a vstemplate alone. 简短的答案是:不能仅使用vstemplate将文件定向到项目的子文件夹。

If you don't mind writing a VS extension, you could try this approach which will create the file in the desired subfolder by replacing the "Add New Item" command in Solution Explorer with your own implementation: 如果您不介意编写VS扩展名,则可以尝试以下方法,该方法将用自己的实现替换“解决方案资源管理器”中的“添加新项”命令,从而在所需的子文件夹中创建文件:

  1. Override the "Add New Item" command with your own event handler (Command GUID: {5EFC7975-14BC-11CF-9B2B-00AA00573819}, ID: 220) http://social.msdn.microsoft.com/Forums/eu/vsx/thread/c0e7de35-73d7-441a-979d-f5e359896b80 ) 使用您自己的事件处理程序覆盖“添加新项”命令(命令GUID:{5EFC7975-14BC-11CF-9B2B-00AA00573819},ID:220) http://social.msdn.microsoft.com/Forums/eu/vsx / thread / c0e7de35-73d7-441a-979d-f5e359896b80
  2. In your event handler, pre-select the subfolder in the Solution Explorer Hierarchy (see http://social.msdn.microsoft.com/Forums/en/vsx/thread/0bef0d6e-c416-4e09-989f-5c2da7379e04 ) 在事件处理程序中,在解决方案资源管理器层次结构中预选择子文件夹(请参阅http://social.msdn.microsoft.com/Forums/en/vsx/thread/0bef0d6e-c416-4e09-989f-5c2da7379e04
  3. Invoke the IVsAddProjectItemDlg.AddProjectItemDlg method, optionally specifying your project item template as the default selected item (see http://social.msdn.microsoft.com/Forums/en/vsx/thread/f24dd433-1522-47ad-bd02-067b13391527 ) 调用IVsAddProjectItemDlg.AddProjectItemDlg方法,可以选择将项目项模板指定为默认的选定项(请参阅http://social.msdn.microsoft.com/Forums/en/vsx/thread/f24dd433-1522-47ad-bd02-067b13391527

The downside to this approach is that every new project item will be added to the project subfolder. 这种方法的缺点是,每个新项目都将添加到项目子文件夹中。 To avoid this, you could add a new context menu command to the Solution Explorer instead of overriding "Add New Item". 为了避免这种情况,您可以向解决方案资源管理器中添加新的上下文菜单命令,而不是覆盖“添加新项”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM