Click here to Skip to main content
13,151,514 members (47,905 online)
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 7 Feb 2005

VS.NET Add-In for creating functions

, 7 Feb 2005
Rate this:
Please Sign up or sign in to vote.
Writing add-ins for VS.NET 2003.

Dialog on click of the command


This article can be a template for writing your own add-ins for Visual Studio .NET 2003. I’ve explained here with an example which helps to copy a bunch of code lines into a new function. This add-in is built with a GUI where you need to input function name, access type and data type.


This add-in contains a command “Add To Function”. This is made visible once you right click after selecting a bunch of lines together. This command will open a dialog where you need to enter the function name, access modifier and return type.

Menu text

On clicking the “Add To Function” link, the pop up dialog seen above will be opened.

Why Add-in?

It’s an amazing and powerful scheme that allows a plug-in developer have various degrees of power. It allows a developer to customize the VS.NET IDE according to the need, and helps in faster development.

How to create the add-in?

In VS.NET 2003, you can find a project template for Visual Studio .NET add-in. Select that and start creating your add-ins.

Dialog on click of the command

This will create an add-in project, and a setup project which helps to wrap up the application to the setup file. After installing the application in the machine, restart VS.NET to get the add-in commands in the IDE.

To reset the toolbars, you need to run DEVENV /SETUP from command prompt. This can be done by navigating to the “…\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE”, and typing DEVENV /SETUP from the command window.

Dialog on click of the command

My Add-in

Helps in creating the function and copying a set of code to the function. Sometimes, we may need to wrap a bunch of code lines to another function. This add-in helps in achieving that.

    CommandBar commandBar = (CommandBar)commandBars["Code Window"];
    Command command=commands.AddNamedCommand(addInInstance,"AddToNew","Add To
                    Function", "",true,1554,ref contextGUIDS,
    CommandBarControl commandBarControl = command.AddControl(commandBar, 1);

Piece of code when the command is invoked:

public void Exec(string commandName, EnvDTE.vsCommandExecOption 
         executeOption, ref object varIn, ref object varOut, ref bool handled)
  handled = false;
  if(executeOption == EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault)
    if(commandName == "FunctionsAddIn.Connect.AddToNew")
        bool result = AddToNewFunc();
        handled = true;
        TextDocument doc = 
          as Text Document;

The AddToNewFunc takes care of formatting the text inside the class file.


Hope this article will guide you to create an add-in of your own interest/usage. You can download the source code here and mail back any queries to


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United States United States
"Variety is the spice of life", I always believe in this in whatever I do.

I started my IT career back in 99 as faculty. I love those moments, when I use to educate oracle for a group of account students. Perhaps the best moment in my IT life till day. Now currently doing my services for accenture, chennai facility.

I'm strong admirer of C# and C++.

I do blog at

You may also be interested in...


Comments and Discussions

GeneralThank you Pin
xibeifeijian3-Jan-07 21:54
memberxibeifeijian3-Jan-07 21:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170924.2 | Last Updated 7 Feb 2005
Article Copyright 2005 by Thoths
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid