Click here to Skip to main content
15,886,806 members
Articles / Programming Languages / C#
Tip/Trick

Visual Studio 2010 Solution Creator AddIn

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
3 May 2012CPOL 12.4K   5   1
VS2010 AddIn that allows to create a solution adding multiple projects at same time

Introduction

When you have a lot of projects, and create a "Blank Solution" on Visual Studio, you need to add the projects one by one, selecting the "*.csproj", because the VS dont allow to add more than one project at same time to the solution.

Using this addin, you can select the projects root folder, and it will search for projects and show it in a grid, and you can select then and the VS Solution will be created.

Using the code 

Creating a AddIn project in VS2010 you will be able to do something like this:
C#
/// <summary>Implements the Exec method of the IDTCommandTarget interface. This is called when the command is invoked.</summary>
/// <param term='commandName'>The name of the command to execute.</param>
/// <param term='executeOption'>Describes how the command should be run.</param>
/// <param term='varIn'>Parameters passed from the caller to the command handler.</param>
/// <param term='varOut'>Parameters passed from the command handler to the caller.</param>
/// <param term='handled'>Informs the caller if the command was handled or not.</param>
/// <seealso class='Exec' />
public void Exec(string commandName, vsCommandExecOption executeOption, 
       ref object varIn, ref object varOut, ref bool handled)
{
    handled = false;
    if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
    {
        if(commandName == "SlnCreator.Connect.SlnCreator")
        {
            handled = true;
            Menu m = new Menu();
            if (m.ShowDialog() == DialogResult.OK)
            {
                List<string> files = m.Paths;
                List<string> solFolders = new List<string>();
                string solName = m.SolutionPath;
                bool createSolFolder = m.CreateSolFolders;

                Solution2 s = (Solution2)_applicationObject.Solution;
                Project prj;
                SolutionFolder sf = null;

                s.Create(Path.Combine(Path.GetDirectoryName(solName), 
                  Path.GetFileNameWithoutExtension(solName)), 
                  Path.GetFileNameWithoutExtension(solName));

                foreach (string file in files)
                {
                    if (createSolFolder)
                    {
                        string solFolder = GetSolutionFolderName(file);
                        if (solFolders.Contains(solFolder) == false)
                        {
                            solFolders.Add(solFolder);
                            prj = s.AddSolutionFolder(solFolder);
                            sf = (SolutionFolder) prj.Object;
                            sf.AddFromFile(file);
                        }
                        else
                        {
                            sf.AddFromFile(file);
                        }
                    }
                    else
                    {
                        s.AddFromFile(file);
                    }
                }
                Directory.CreateDirectory(Path.GetDirectoryName(solName));
                s.SaveAs(solName);
                return;
            }
        }
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Brazil Brazil
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionGreat idea Pin
Rudi Breedenraedt9-May-12 13:35
Rudi Breedenraedt9-May-12 13:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.