12 Oct 2013

Visual Studio Extension for adding multiple projects to a solution

Background

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.

Almost Ranting

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.

Configuration Settings

The settings for the extension are saved into an XML file located at %AppData%\Cyotek\VisualStudioExtensions\AddProjects\config.xml.

<?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>

The 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 csproj!

The Projects element stores the MRU list of projects.

Closing

That's pretty much it - it's a very simple extension, but potentially a starting point for something more interesting.

You can download the code or the compiled VSIX installer from the links below.

Related articles you may be interested in:

Downloads

Cyotek.VisualStudioExtensions.AddProjects.vsix

Signed Visual Studio extension installer for the Visual Studio Extension for adding multiple projects to a solution blog post.

18 April 2014 87.64 KB
Cyotek.AddProjects.zip

Source code for the Visual Studio Extension for adding multiple projects to a solution blog post.

12 October 2013 41.65 KB

Comments

  • Gravatar
    # Param
    28/01/2014 11:19

    Good and usefull ... thanks

  • Gravatar
    # Param
    28/01/2014 12:26

    Its really awesome tool. I tried many other urls, but i could not get the proper solution. Finally i found it here.. thanks Richard.

  • Gravatar
    # your name
    11/02/2014 21:55

    Thanks for this

  • Gravatar
    # Nix
    18/03/2014 14:57

    Very useful tool, thanks for sharing it :)

  • Gravatar
    # Dwain Browne
    03/05/2014 18:59

    You are a life saver!! I was seriously beginning to question if my job was to code or add references to projects. Thanks a mill.

  • Gravatar
    # m.qayyum
    13/05/2014 13:03

    helped alot, thanks

  • Gravatar
    # Victor
    17/07/2014 20:12

    Thanks a lot. This saved me a lot of time - I wish I'd discovered it earlier!

  • Gravatar
    # Zoltán Lehóczky
    08/09/2014 15:14

    Would you add this to the VS Gallery please? Would also gain some visibility.

    • Gravatar
      # Richard Moss
      08/09/2014 19:05

      I've been meaning to do this for ages. Of course, I've been meaning to update it to use WPF and a bunch of other stuff for ages too and still haven't. But I've now uploaded it to the gallery - http://visualstudiogallery.msdn.microsoft.com/dc3adb4b-3b94-4ca0-97fd-3c817bd14a77. And who knows, maybe I'll find some time to update it further in future.

      Regards;
      Richard Moss

  • Gravatar
    # Michael Clark
    26/09/2014 12:32

    Thanks for this. It has saved me from doing this manually for over 100 projects. Could you allow ordering the results by path to allow us to exclude particular areas of the codebase?

    • Gravatar
      # Richard Moss
      26/09/2014 16:40

      Thanks for the comment, glad you found it useful. And your suggestion is definitely reasonable, I'll be sure to add that to the next update!

      Regards;
      Richard Moss

Leave a Comment

While we appretiate comments from our users, please follow our posting guidelines. Have you tried the Cyotek Forums for support from Cyotek and the community?