Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Visual Studio 2010 Solution Creator AddIn

0.00/5 (No votes)
3 May 2012 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:
/// <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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here