I'm writing a little extension for Visual Studio 2015. I added a VSPackage to to embed some CustomCommands on the Shortcut Menu you get when you RightClick on a Project or a Folder inside the Solution Explorer.
What I would like to do now is "open the Add New Item dialog and select the one of the templates I've installed with this VSPackage".
This is the Code I use to initialize my commands:
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);
}
The CreateCustomTemplate callback code is this:(for the moment I simply create a messageBox, just to ensure it works)
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);
}
So, to recap, how do I open the Add New Item dialog box and select a specific item template?
As an example, when you try to create a Class or a UserControl right-clicking on a folder in the solution explorer
You obtain something similar to this:
And this is, exactly, what I'm trying to achieve. Obviously I would like to create my own template and not the UserControl.
If you need any clarification feel free to ask. Thank you in advance for any suggestion
In the end I resolved my problem.
Unfortunately the command File.AddNewItem (or Project.AddNewItem) is not suitable in my case as I want to see the AddNewFile Dialog (and these command simply adds the item to the specified project).
I Found the solution digging the web, exactly here, specifically thanks to the answer of Vladimir.Ilic.
This is the code I use to achieve my goal:
Big thanks to the ones that passed by and that have tried (or even thinked) to help!
Hope this helps someone,
Sincerely