My solutions have lots of references to other projects, either common libraries or unit testing libraries. Neither of these scenarios lend well to manual binary references or NuGet packages, so I have lots of source code projects loaded for each solution.
When creating a new solution (or retro fitting an existing solution to use new libraries), I end up using File | Add | Existing project a lot. As I was curious about how extensions in Visual Studio worked, I decided to write a very simple one to ease the grunt work of adding multiple common projects.
The last time I wrote an extension (or addin as they were called back then :)) for an IDE was vbCodeShield for Visual Basic 6 and that was years ago. I was incredibly surprised to find that writing an extension for Visual Studio is pretty much the same as it was (if not worse) - a horrible mass of unintuitive COM interfaces and clunky code. Whatever happened to the managed dream?
On the plus side, they are much easier to debug than I remember VB6 addins being. Or at least, they would be if Resharper didn't raise continuous exceptions while running in Visual Studio's Experimental Instance.
Still, I created the extension without too much pain, although I have to say it's some of the code I'm least proud of, and I'm certainly not going to walk through the code on this blog.
I gather you're supposed to use WPF to write extensions, but well... I wasn't going to learn WPF and the DTE at the same time. I actually tried (the aborted attempt is still in the source tree) to use a WPF dialog as recommended by the MSDN docs, but after finding simple things like checked list boxes (or even just list views with checkboxes) seemed to have a learning curve equal to the Moon landing, I went back to Windows Forms and had it knocked up in no time.
The code is messy, isn't using WPF, doesn't have a great deal of exception handling, and is full of artefacts from the wizard generation. But, it does seem to work.
Using the extension
To use the extension, open the Tools menu and choose Add Projects. This will open a lovely unthemed Windows Forms dialog containing an empty list of projects.
Adding a single project to the MRU
To add a single project to the list, click the Add File button then select the project you want to include.
Adding multiple projects to the MRU
To add multiple projects to the list, click the Add Folder button, then select a folder. After you've selected a folder, all projects in this folder and its subfolders will be added to the list.
Removing projects from the MRU
You can remove projects from the list, just select them and press the Delete key or the Remove button.
Adding projects to your solution
Just place tick each project you want to add to your solution, then click the OK button. It will then try and add each selected project to your solution, skipping any that are already present.
The settings for the extension are saved into an XML file located at
<?xml version="1.0"?> <ExtensionSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Filter>C# Projects (*.csproj)|*.csproj|All Files (*.*)|*.*</Filter> <Projects> <string>C:\Checkout\cyotek\source\Libraries\Cyotek.ApplicationServices\Cyotek.ApplicationServices.csproj</string> <string>C:\Checkout\cyotek\source\Libraries\Cyotek.ApplicationServices.Commands\Cyotek.ApplicationServices.Commands.csproj</string> <!-- SNIP --> <string>C:\Checkout\cyotek\source\Libraries\Cyotek.Windows.Runtime.Support\Cyotek.Windows.Runtime.Support.csproj</string> <string>C:\Checkout\cyotek\source\Libraries\Cyotek.Windows.Runtime.Testing\Cyotek.Windows.Runtime.Testing.csproj</string> </Projects> </ExtensionSettings>
Filter element lets you specify the filter for the Add File dialog, and is also used by Add Folder to search for appropriate files - if you write in Visual Basic rather than C# you'll probably want to change the filter to be
vbproj rather than
Projects element stores the MRU list of projects.
That's pretty much it - it's a very simple extension, but potentially a starting point for something more interesting.
The best place to get the extension is from the extension page on the Microsoft Visual Studio Gallery. This also ensures you get notifications when the extension is updated. (Don't forget to post a review!)
You can also grab the source directly from our GitHub page.
Legacy links available below are no longer maintained.
- 12Oct2013 First published
- 14Oct2014 Updated to include Visual Studio Gallery and GitHub links
Related articles you may be interested in
Signed Visual Studio extension installer for the Visual Studio Extension for adding multiple projects to a solution blog post.
Source code for the Visual Studio Extension for adding multiple projects to a solution blog post.