Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 868257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:06:34+00:00 2026-05-15T10:06:34+00:00

I want to add a new option in Visual Studio 2010’s solution explorer’s context

  • 0

I want to add a new option in Visual Studio 2010’s solution explorer’s context menu for a specific file type. So for example, right clicking on a *.cs file will show the existing context menu plus “my new option”.

I’m wondering what the code would look like; and would love a pointer to a good reference for developing visual studio plug-ins. The tutorials/references I’m seeing are conspicuously horrid.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:06:35+00:00Added an answer on May 15, 2026 at 10:06 am

    It took me about 5 hours to do this.

    There are 2 options, Visual studio Add-in (or shared Add-in) vs Visual studio package.

    The package is far more complicated to give you far more control, but for a context menu on the solution explorer it is not needed.

    So new project-> Other Project Types -> Extensibility -> Visual Studio Add-in.

    Here’s a walk-through – Link

    Also This one I followed some – Link

    I recommend you leave on the option for add to tools menu until you have the context menu working, or to provide a place to put a settings dialog (if you don’t write a Tool-> options page.

    Here’s the connection code:

      _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;
            if (connectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                object[] contextGUIDS = new object[] { };
                Commands2 commands = (Commands2)_applicationObject.Commands;
                string toolsMenuName = "Tools";
    
                //Place the command on the tools menu.
                //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
                Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];
    
                //Find the Tools command bar on the MenuBar command bar:
                CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
                CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;
                // get popUp command bars where commands will be registered.
                CommandBars cmdBars = (CommandBars)(_applicationObject.CommandBars);
                CommandBar vsBarItem = cmdBars["Item"]; //the pop up for clicking a project Item
                CommandBar vsBarWebItem = cmdBars["Web Item"];
                CommandBar vsBarMultiItem = cmdBars["Cross Project Multi Item"];
                CommandBar vsBarFolder = cmdBars["Folder"];
                CommandBar vsBarWebFolder = cmdBars["Web Folder"];
                CommandBar vsBarProject = cmdBars["Project"]; //the popUpMenu for right clicking a project
                CommandBar vsBarProjectNode = cmdBars["Project Node"];
    
                //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
                //  just make sure you also update the QueryStatus/Exec method to include the new command names.
                try
                {
                    //Add a command to the Commands collection:
                    Command command = commands.AddNamedCommand2(_addInInstance, "HintPaths", "HintPaths", "Executes the command for HintPaths", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
    
                    //Add a control for the command to the tools menu:
                    if ((command != null) && (toolsPopup != null))
                    {
                        //command.AddControl(toolsPopup.CommandBar, 1);
                        command.AddControl(vsBarProject); 
                    }
                }
                catch (System.ArgumentException argEx)
                {
                    System.Diagnostics.Debug.Write("Exception in HintPaths:" + argEx.ToString());
                    //If we are here, then the exception is probably because a command with that name
                    //  already exists. If so there is no need to recreate the command and we can 
                    //  safely ignore the exception.
                }
            }
        }
    

    This code checks to see if what the user has selected is a project for instance:

      private Project GetProject()
        {
            if (_applicationObject.Solution == null || _applicationObject.Solution.Projects == null || _applicationObject.Solution.Projects.Count < 1)
                return null;
            if (_applicationObject.SelectedItems.Count == 1 && _applicationObject.SelectedItems.Item(1).Project != null)
                return _applicationObject.SelectedItems.Item(1).Project;
            return null;
        }
    

    Note that certain string names in your code have to match up and I’m not sure which ones they are quite yet as I just did this yesterday.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a new time-field to a an existing MySQL-table that is
I have dbml with single table users i want add partial class for User
I want to add a column to an existing legacy database and write a
I want to add a constant value onto an incoming bound integer. In fact
I want to add a scheduled task to a client's ASP.NET app. These posts
I want to add a mailto link on our web page. I want to
I want to add a property to my User model that returns the number
I want to add a comma in the thousands place for a number. Would
I want to add same field to multiple tables. Can I do this with
I want to add my own member to the StringBuilder class, but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.