我正在为 Visual Studio 2015 编写一个小扩展。我添加了一个 VSPackage 以在您在解决方案资源管理器中右键单击项目或文件夹时获得的快捷菜单上嵌入一些自定义命令。
我现在想做的是“打开添加新项目对话框并选择我使用此 VSPackage 安装的模板之一”。
这是我用来初始化命令的代码:
private TemplateCommand(Package package)
{
if (package == null)
throw new ArgumentNullException(nameof(package));
_package = package;
var commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService == null)
return;
AddCommand(commandService, CommandId, CreateCustomTemplate);
}
CreateCustomTemplate 回调代码是这样的:(目前我只是创建一个消息框,只是为了确保它有效)
private void CreateCustomTemplate(object sender, EventArgs eventArgs)
{
//TODO: code to replace!
var message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.CreateCustomTemplate()", GetType().FullName);
// Show a message box to prove we were here
VsShellUtilities.ShowMessageBox(
ServiceProvider,
message,
"CREATE CustomTemplate",
OLEMSGICON.OLEMSGICON_INFO,
OLEMSGBUTTON.OLEMSGBUTTON_OK,
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
}
那么,回顾一下,如何打开“添加新项目”对话框并选择特定的项目模板?
例如,当您尝试在解决方案资源管理器中右键单击文件夹创建 Class 或 UserControl
这正是我想要实现的目标。显然我想创建自己的模板而不是 UserControl。
如果您需要任何澄清,请随时询问。提前感谢您的任何建议