Search code examples
c#.netadd-invisual-studio-addins

Get Project form "Project" CommandBar button


I'm developing an addin for VS 2012. I added a button and command to the Project command bar.

Now I have button in right-click menu after clicking on Project.

All I want to do for now is list all *.cs files from the project on which that button was clicked and have access to edit them.

I need that info in "Exec" function that is "catching" my command.

How to do it?

Pieces of my code:

_CommandBars cmdBars = (_CommandBars)_applicationObject.CommandBars;

CommandBar vsBarProject = cmdBars["Project"];

CommandBarPopup pluginProjectFolderPopup = (CommandBarPopup)vsBarProject.Controls.Add(MsoControlType.msoControlPopup, System.Reflection.Missing.Value, System.Reflection.Missing.Value, 1, true);

pluginProjectFolderPopup.Caption = "Plugin";

try
{
    Command command = commands.AddNamedCommand2(_addInInstance, "TestRightClickProject", "Plugin test", "Testing right click command on code window", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStyleText, vsCommandControlType.vsCommandControlTypeButton);
    if ((commands != null) && (pluginProjectFolderPopup != null))
    {
        command.AddControl(pluginProjectFolderPopup.CommandBar, 1);
    }
}
catch (System.ArgumentException)
{
}

UPDATE: I have no choise. I have to use addins


Solution

  • Look at the answer to this question:

    Visual Studio 2010 Plug-in - Adding a context-menu to the Solution Explorer

    Once you determine the project being selected (see

    _applicationObject.SelectedItems.Item(1).Project
    

    )

    You can use ProjectKinds.vsProjectKindSolutionFolder to get the project folder (see How to get folders under projects? )

    Then iterate through the desired folder and subfolders.