/// <summary>
        /// Converts the Visual Studio Solution from one version to another
        /// </summary>
        /// <param name="objVSSolnInfo" type="ProjectConverter.VSSolutionInfo">
        ///     <para>
        ///
        ///     </para>
        /// </param>
        /// <param name="ConvertTo" type="ProjectConverter.Versions">
        ///     <para>
        ///
        ///     </para>
        /// </param>
        /// <returns>
        ///     A ProjectConverter.VSSolutionInfo value...
        /// </returns>
        public static VSSolutionInfo ConvertVSSolution(VSSolutionInfo objVSSolnInfo, Versions ConvertTo)
        {
            VSSolutionInfo vsSolnInfo = new VSSolutionInfo(objVSSolnInfo.SolnFilePath);

            VSSolutionFormat vsSolnFormat = VSSolutionFormat.VSSolutionFormatFactory((int)ConvertTo);


            switch (ConvertTo)
            {
            case Versions.Version8:
                vsSolnInfo.SolnFileVersionHeader = vsSolnFormat.SolnHeader;
                vsSolnInfo.SolnFileFormatHeader  = vsSolnFormat.SolnFormat;
                break;

            case Versions.Version9:
                vsSolnFormat = VSSolutionFormat.VSSolutionFormatFactory(9);
                vsSolnInfo.SolnFileVersionHeader = vsSolnFormat.SolnHeader;
                vsSolnInfo.SolnFileFormatHeader  = vsSolnFormat.SolnFormat;
                break;

            case Versions.Version10:
                vsSolnFormat = VSSolutionFormat.VSSolutionFormatFactory(10);
                vsSolnInfo.SolnFileVersionHeader = vsSolnFormat.SolnHeader;
                vsSolnInfo.SolnFileFormatHeader  = vsSolnFormat.SolnFormat;
                break;

            case Versions.Version11:
                vsSolnFormat = VSSolutionFormat.VSSolutionFormatFactory(11);
                vsSolnInfo.SolnFileVersionHeader = vsSolnFormat.SolnHeader;
                vsSolnInfo.SolnFileFormatHeader  = vsSolnFormat.SolnFormat;
                break;

            case Versions.Version12:
                vsSolnFormat = VSSolutionFormat.VSSolutionFormatFactory(11);
                vsSolnInfo.SolnFileVersionHeader = vsSolnFormat.SolnHeader;
                vsSolnInfo.SolnFileFormatHeader  = vsSolnFormat.SolnFormat;
                break;
            }//switch

            return(vsSolnInfo);
        }//method: ConvertVSSolution()
Example #2
0
        }     //property: SolutionInfo
        #endregion

        #region Methods
        /// <summary>
        /// Populates the Solution Information
        /// </summary>
        private void PopulateSolutionInfo(string strSolutionFilePath)
        {
            m_vsSolutionInfo  = new VSSolutionInfo(strSolutionFilePath);
            this.SolutionInfo = m_vsSolutionInfo;
        }//method: PopulateSolutionInfo()
Example #3
0
        /// <summary>
        /// Event handler for the Conversion
        /// to convert the Visual Studio Solution as well as all of the associated projects
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bnConvert_Click(object sender, System.EventArgs e)
        {
            double ExistingVersion   = 0;
            int    convertedProjects = 0;

            // A quick sanity check
            if (tbSolutionFile.Text == "")
            {
                MessageBox.Show("Please enter a valid Visual Studio solution file", "Oops", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (ConvertTo == Versions.NotSelected || lbVersion.SelectedIndex == -1)
            {
                MessageBox.Show("Please enter a select a version to convert to", "Oops", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // Let's make sure this is valid solution file
            try
            {
                ExistingVersion = this.SolutionFormatVersion;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error reading the solution file" + "\r" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Did you ask to make a backup copy?
            if (cbBackup.Checked)
            {
                try
                {
                    ConvertVSProjects.MakeBackup(tbSolutionFile.Text, ExistingVersion);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not create backup file" + "\r" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            VSSolutionInfo vsSolnInfo = new VSSolutionInfo(tbSolutionFile.Text);


            //Read the properties of the Visual Studio Solution file
            VSSolutionInfo convertedSolnInfo = VSSolutionInfo.ConvertVSSolution(vsSolnInfo, ConvertTo);


            //Convert all of the projects in the solution
            foreach (var projFile in convertedSolnInfo.SupportedProjectConvList)
            {
                //Perform a backup of the project file prior to attempting the conversion
                if (cbBackup.Checked)
                {
                    ConvertVSProjects.MakeBackup(projFile, ExistingVersion);
                }//if

                // convert the VB/C# project files
                if (ConvertVSProjects.ConvertProject(projFile, ConvertTo, chkRemoveScc.Checked))
                {
                    convertedSolnInfo.ConvertedProjectCount++;
                }//if

                //TODO: Log the errors to a log file instead
                //MessageBox.Show("Could not convert project file" + "\r" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }//foreach

            //Set the value to the total converted projects
            convertedProjects = convertedSolnInfo.ConvertedProjectCount;

            //Convert the Visual Studio Solution file
            convertedSolnInfo.ConvertVSSolution();

            // Tell 'em what we did
            string strMessage = string.Format("Converted 1 solution and {0} project file{1} out of a total of {2} project{3} in the solution", convertedProjects,
                                              ((convertedProjects > 1) ? "s" : "").ToString(),
                                              convertedSolnInfo.TotalProjectCount,
                                              ((convertedSolnInfo.TotalProjectCount > 1) ? "s" : "").ToString());

            MessageBox.Show(strMessage, "Sucess", MessageBoxButtons.OK, MessageBoxIcon.Information);


            // reload the version (in case you want to hit the convert button a 2nd time)
            LoadChoices(this.SolutionFormatVersion);


            // if started from a shell extension, then close when we're done
            if (Environment.GetCommandLineArgs().Length == 2)
            {
                this.Close();
            }
        }