Addin to Extend Solution Explorer with "Open Appropriate Solution" if available?
Imagine a folder structure that contains over 200 project solution files, all from the same software. Most of them generate shared libraries that are referenced by other projects that are contained in their own solutions.
Wouldn't be great if it were possible to right-click on such a reference assembly in the solution explorer and then have a context menu item such as "Open Solution" and "Open Solution in a New Instance of Visual Studio" (something like this )?
For this to work, the addin must be configured with some kind of base directory. From there it should create a collection of all available solution files and contained projects. When the link is right-clicked, it should scan the project files for the appropriate output and - if found - present menu items to directly open the corresponding solution (perhaps this information could also be preprogrammed).
Well ... have any of you already created such an add-on? Does anyone possibly know of an addon that already does something like this?
If none of these questions answered yes: Can someone point me to how to expand the context menu for solution researchers based on given preconditions?
a source to share
Afaik you can't do it with VS MEF extension, but it probably isn't that hard to do with VS add-in.
-
Use the MZTools samples / templates to write the part that will add your menu to the appropriate command line (this is the popup context menu that includes the Solution Explorer commands). I got hooked on
Solution
andProject
. I am assuming there is also a commandBar namedReference
. The following codeApplicationObject
is of typeEnvDTE
Here is some code to find the required command line:private void IterateAllCommandBars( ) { var commandBars =(CommandBars)ApplicationObject.CommandBars; Debug.Indent( ); foreach (CommandBar commandBar in commandBars) { Debug.WriteLine(commandBar.Name); } Debug.Unindent( ); }
-
When your extension is loaded (usually in
OnStartupComplete
), you can search for your preconditions and set up a dictionary that displays a link to the solution path. -
Use the QueryStatus call that is invoked on add to enable / disable the menu based on which the link is selected, if any. For example, I get the selected project, if any:
private static Project GetProject(DTE applicationObject) { 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; }
-
Execute the command you want to invoke when the user clicks a valid option. I'm not sure how or if you could open this solution in an existing VS instance, but opening in a new VS would be easy.
Process.Start(ProjectFullPath);
or it could be SolutionFullPath.
a source to share