Partager via


New Add-in sample – Add Code Wizard

I originally wrote this sample for the wizards chapter of our book, but it really did not fit into the flow of the rest of the chapter. It was a tough cut, but it had to be done. I forgot about it until recently while doing some hard disk clean-up.

 

So what does this sample do? Visual Studio allows you to create wizards and templates for adding new projects or adding items to a project, but it does not allow you to create templates and wizards for bits of code within a file. This Add-in enables that. Suppose you have a C++ project and you want to insert a new class into an existing file. Simply open your file, make it the active document, and select the Tools | Add Code Wizard menu item. You will be presented with an Add Item-esque dialog box where you can select a template. If the template has the .vsz extension, then the file is launched as a wizard. If the file is of any other type, then it is inserted into the text document.

 

The sample contains a demo wizard which will insert a class into a C# file, but it will prompt you for the name of the class first (a template file does not do any replacements like changing the class name). To create your own template, simply drop a template file into the appropriate sub-folder in the Templates directory. For example, suppose you used the default install location to install the Add-in into, you can create a new template for the C# file type at “C:\Program Files\Default Company Name\AddCodeWizardAddInSetup\Templates\cs\General”. Have a file type that is not represented by the default templates? Simply create a new folder – for example, you can add a template for .aspx files by creating a “C:\Program Files\Default Company Name\AddCodeWizardAddInSetup\Templates\aspx\General” folder. Also, anything after the file extension portion of the path will appear as a folder on the left side of the Add Code dialog box.

 

The code and an msi file can be found on GotDotNet Workspaces (https://www.gotdotnet.com/community/workspaces/), just search for Add Code Wizard. Eventually this will probably become a VS Power Toy, but for now it is a beta tool. Have any enhancements, templates, or wizards you would like to add? Send them along and I will try to add them.

Comments

  • Anonymous
    April 26, 2004
    I need a server control deployment wizard REALLY bad.
  • Anonymous
    September 06, 2010
    Thanks for posting! I really enjoyed the report. I've already bookmark this article.