Click here to Skip to main content
Click here to Skip to main content

Visual Studio 2010 Solution Creator AddIn

, 3 May 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

igorvelho
Software Developer
Brazil Brazil
No Biography provided

Comments and Discussions

 
QuestionGreat idea PinmemberRudi Breedenraedt9-May-12 14:35 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 3 May 2012
Article Copyright 2012 by igorvelho
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid