Exemplo n.º 1
0
        private static void SwitchToNuGetMode(OperationContext context)
        {
            if (String.IsNullOrEmpty(context.TfsServerUri))
            {
                GeneralUtils.ShowMessage("TFS server uri is missing in Tools->Options->Nuget Tool page", OLEMSGICON.OLEMSGICON_WARNING);
            }

            using (GeneralUtils.StartAnimation())
                using (var progress = GeneralUtils.StartProgressProgress("Back to NuGet",
                                                                         context.Projects.LoadedProjects.Length + 1))
                {
                    foreach (ProjectInfo project in context.Projects.LoadedProjects)
                    {
                        try
                        {
                            progress.Increment();
                            GeneralUtils.ReportStatus($"Switching [{project.Name}]");
                            SwitchProjectToNuGet(project, context);
                        }
                        catch (Exception ex)
                        {
                            GeneralUtils.ShowMessage("Failed to convert project: " + project.Name + ", Error message: " + ex.Message, OLEMSGICON.OLEMSGICON_CRITICAL);
                        }
                    }

                    progress.Increment();
                    context.Projects.ReOpenSolution();
                    GeneralUtils.ShowMessage("Conversion to NuGet mode finished successfully.");
                }
        }
 private static async TPL.Task BuildProjectsWithNoPackages(
     OperationContext context)
 {
     using (var progress = GeneralUtils.StartProgressProgress("Build", context.Projects.LoadedProjects.Length))
     {
         int i = 0;
         foreach (ProjectInfo project in context.Projects.LoadedProjects)
         {
             i++;
             progress.Report(i);
             if (!project.ProjectBuilt)
             {
                 // TODO: 2017-01 Bnaya, use UpdateNuGetDependencies instead of AddBuildEvents
                 //using (await UpdateNuGetDependencies(project, context, context.PackagesUpdatedSoFar))
                 using (AddBuildEvents(project, context, context.PackagesUpdatedSoFar))
                 {
                     if (await context.Projects.BuildProject(project))
                     {
                         project.ProjectBuilt = true;
                     }
                     else
                     {
                         GeneralUtils.ShowMessage($"Failed to build project {project.Name}", OLEMSGICON.OLEMSGICON_CRITICAL);
                     }
                 } // RemoveBuildEvents(project);
             }
         }
     }
 }
Exemplo n.º 3
0
 private static void SwitchToDebugMode(OperationContext context)
 {
     using (GeneralUtils.StartAnimation())
         using (var progress = GeneralUtils.StartProgressProgress("To Project Reference",
                                                                  context.Projects.LoadedProjects.Length))
         {
             foreach (ProjectInfo project in context.Projects.LoadedProjects)
             {
                 try
                 {
                     progress.Increment();
                     GeneralUtils.ReportStatus($"Switching [{project.Name}]");
                     SwitchProjectToDebug(project, context);
                 }
                 catch (Exception ex)
                 {
                     GeneralUtils.ShowMessage("Failed to convert project: " + project.Name + ", Error message: " + ex.Message, OLEMSGICON.OLEMSGICON_CRITICAL);
                 }
             }
         }
     context.Projects.ReOpenSolution();
     GeneralUtils.ShowMessage("Conversion to debug mode finished successfully.");
 }
        /// <summary>
        /// Handle the process of Updating the NuGet packages.
        /// </summary>
        /// <param name="preRelease">if set to <c>true</c> [pre release].</param>
        public static async void UpdateNuGetPackages(bool preRelease)
        {
            using (GeneralUtils.StartAnimation())
                using (var progress = GeneralUtils.StartProgressProgress("NuGet Upgrade", UPDATE_NUGET_COUNT))
                {
                    try
                    {
                        GeneralUtils.ReportStatus($"Start NuGet Upgrade: pre-release = {preRelease}");
                        OperationContext context = LoadNuGetPackages(preRelease);

                        #region Validation

                        if (context == null)
                        {
                            return;
                        }

                        if (context.Projects.LoadedProjects.Length == 0)
                        {
                            return;
                        }

                        if (context.Projects.IsSolutionInDebugMode())
                        {
                            GeneralUtils.ShowMessage("Solution is in debug mode. Switch back to NuGet mode before updating the packages.", OLEMSGICON.OLEMSGICON_WARNING);
                            return;
                        }

                        if (!await context.Projects.BuildSolution())
                        {
                            if (MessageBox.Show(@"Make sure that the solution is build 
with no errors, before NuGet upgrade!
Do you want to continue", "Pre build solution",
                                                MessageBoxButtons.YesNo,
                                                MessageBoxIcon.Question) == DialogResult.No)
                            {
                                return;
                            }
                        }

                        #endregion // Validation

                        // Build only packages with corresponding projects
                        // in the current solution
                        var packagesToBuild = (from p in context.PackagesInfo
                                               where p.ProjectInfo != null
                                               select p).ToList();

                        // Add NuGet packages that have no corrseponding projects in current solution,
                        // but depend on other NuGet packages that need to upgrade
                        var dependentPackagesWithoutProjects = GetDependentPackagesWithoutProjects(context);
                        packagesToBuild.AddRange(dependentPackagesWithoutProjects);

                        #region Validation

                        if (packagesToBuild.Count == 0)
                        {
                            GeneralUtils.ShowMessage(@"No NuGet package needs to be updated.
Goto: Tools -> Options -> NuGet Tool
and add path for local NuGet repositories.");
                            return;
                        }

                        #endregion // Validation

                        //RemoveCachedNuGetFiles();
                        context.Projects.CleanSolution();
                        progress.Report(1);

                        using (var currentProgress = GeneralUtils.StartProgressProgress("NuGet: Current", packagesToBuild.Count))
                        {
                            DialogResult result =
                                await BuildAndUpdate(context, packagesToBuild, currentProgress);

                            switch (result)
                            {
                            case DialogResult.Cancel:
                                GeneralUtils.ReportStatus("Operation Canceled");
                                return;

                            case DialogResult.Abort:
                                GeneralUtils.ReportStatus("Operation aborted");
                                return;
                            }
                            currentProgress.Report(packagesToBuild.Count);
                        }

                        progress.Report(5);
                        if (context.ShouldArchiveOldNuGet)
                        {
                            GeneralUtils.ReportStatus($"NuGet: Archive");
                            await CreateArchiveZipFile(context.ArchiveSession);
                        }

                        GeneralUtils.ReportStatus($"NuGet: Build");
                        progress.Report(6);
                        // Build all the other projects that don't have corresponding NuGet packages
                        await BuildProjectsWithNoPackages(context);

                        progress.Report(7);

                        GeneralUtils.ReportStatus($"NuGet: Re-open projects");
                        await TPL.Task.Factory.StartNew(() =>
                                                        context.Projects.ReOpenSolution(),
                                                        TPL.TaskCreationOptions.LongRunning);

                        progress.Report(8);
                        #region Clipboard.SetText(context.ArchiveFolder)

                        try
                        {
                            Clipboard.SetText(context.ArchiveFolder);
                        }
                        catch { }

                        #endregion // Clipboard.SetText(context.ArchiveFolder)

                        GeneralUtils.ShowMessage($@"{context.PackagesUpdatedSoFar.Count} NuGet packages have been updated
Old packages moved to [{context.ArchiveFolder}] + copied to the clipboard");
                    }
                    catch (FileNotFoundException ex)
                    {
                        MessageBox.Show($@"Make sure to build the solution before running the tool

{ex}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
        }