public static void Upgrade(List <IVsProject> projects, UpgradeProgressCallback progressCallback)
        {
            string     solutionDir = Path.GetDirectoryName(Package.Instance.DTE2.Solution.FullName);
            Dispatcher dispatcher  = Dispatcher.CurrentDispatcher;
            Thread     t           = new Thread(() =>
            {
                for (int i = 0; i < projects.Count; ++i)
                {
                    if (progressCallback.Canceled)
                    {
                        break;
                    }

                    IVsProject project = projects[i];
                    string projectName = FileUtil.RelativePath(solutionDir, ProjectUtil.GetProjectFullPath(project));
                    if (Upgrade(project))
                    {
                        EnvDTE.Project p = DTEUtil.GetProject(project as IVsHierarchy);
                        if (p.Globals != null)
                        {
                            foreach (string name in OldPropertyNames)
                            {
                                if (p.Globals.get_VariableExists(name))
                                {
                                    p.Globals[name] = string.Empty;
                                    p.Globals.set_VariablePersists(name, false);
                                }
                            }
                        }
                        Package.Instance.AddIceBuilderToProject(project);
                    }
                    dispatcher.Invoke(
                        new Action(() =>
                    {
                        progressCallback.ReportProgress(projectName, i);
                    }));
                }
                dispatcher.BeginInvoke(new Action(() => progressCallback.Finished()));
            });

            t.Start();
        }
        public static void Upgrade(List<EnvDTE.Project> projects, UpgradeProgressCallback progressCallback)
        {
            String solutionDir = Path.GetDirectoryName(Package.Instance.DTE2.Solution.FullName);
            Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
            Thread t = new Thread(() =>
            {
                for (int i = 0; i < projects.Count; ++i)
                {
                    if (progressCallback.Canceled)
                    {
                        break;
                    }

                    EnvDTE.Project project = projects[i];
                    String projectName = FileUtil.RelativePath(solutionDir, project.FullName);
                    if (Upgrade(project))
                    {
                        if (project.Globals != null)
                        {
                            foreach (String name in ProjectConverter.OldPropertyNames)
                            {
                                if (project.Globals.get_VariableExists(name))
                                {
                                    project.Globals[name] = String.Empty;
                                    project.Globals.set_VariablePersists(name, false);
                                }
                            }
                        }
                        Package.Instance.AddIceBuilderToProject(project);
                    }
                    dispatcher.Invoke(
                        new Action(() =>
                            {
                                progressCallback.ReportProgress(projectName, i);
                            }));
                }
                dispatcher.BeginInvoke(new Action(() => progressCallback.Finished()));
            });
            t.Start();
        }
        public static void Upgrade(Dictionary <string, IVsProject> projects, UpgradeProgressCallback progressCallback)
        {
            Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
            Thread     t          = new Thread(() =>
            {
                try
                {
                    var NuGet = Package.Instance.NuGet;
                    if (!NuGet.IsUserConsentGranted())
                    {
                        Package.WriteMessage("Ice Builder cannot download the required NuGet packages because " +
                                             "\"Allow NuGet to download missing packages\" is disabled");
                        dispatcher.Invoke(new Action(() => progressCallback.Finished()));
                        return;
                    }

                    var DTE     = Package.Instance.DTE;
                    var builder = Package.Instance;
                    int i       = 0;
                    int total   = projects.Count;
                    foreach (var entry in projects)
                    {
                        var project    = entry.Value;
                        var dteProject = project.GetDTEProject();
                        var uniqueName = dteProject.UniqueName;
                        var name       = entry.Key;
                        i++;
                        if (progressCallback.Canceled)
                        {
                            break;
                        }

                        dispatcher.Invoke(
                            new Action(() =>
                        {
                            progressCallback.ReportProgress(name, i);
                        }));

                        try
                        {
                            NuGet.Restore(dteProject);
                        }
                        catch (Exception ex)
                        {
                            Package.WriteMessage(
                                string.Format("\nNuGet package restore failed:\n{0}\n", ex.Message));
                            dispatcher.Invoke(new Action(() => progressCallback.Finished()));
                            break;
                        }

                        if (!NuGet.IsPackageInstalled(dteProject, Package.NuGetBuilderPackageId))
                        {
                            try
                            {
                                DTE.StatusBar.Text = string.Format("Installing NuGet package {0} in project {1}",
                                                                   Package.NuGetBuilderPackageId, name);
                                NuGet.InstallLatestPackage(dteProject, Package.NuGetBuilderPackageId);
                            }
                            catch (Exception ex)
                            {
                                Package.WriteMessage(
                                    string.Format("\nNuGet package zeroc.icebuilder.msbuild install failed:\n{0}\n", ex.Message));
                                dispatcher.Invoke(new Action(() => progressCallback.Finished()));
                                break;
                            }
                        }

                        IceBuilderProjectType projectType = IsIceBuilderEnabled(project);
                        if (projectType != IceBuilderProjectType.None)
                        {
                            bool cpp           = projectType == IceBuilderProjectType.CppProjectType;
                            DTE.StatusBar.Text = string.Format("Upgrading project {0} Ice Builder settings", project.GetDTEProject().UniqueName);

                            var fullPath    = project.GetProjectFullPath();
                            var assemblyDir = project.GetEvaluatedProperty("IceAssembliesDir");
                            var outputDir   = project.GetEvaluatedProperty("IceBuilderOutputDir");

                            var outputDirUnevaluated       = project.GetPropertyWithDefault("IceBuilderOutputDir", "generated");
                            var sourceExt                  = project.GetPropertyWithDefault("IceBuilderSourceExt", "cpp");
                            var headerOutputDirUnevaluated = project.GetProperty("IceBuilderHeaderOutputDir");
                            var headerExt                  = project.GetPropertyWithDefault("IceBuilderHeaderExt", "h");

                            var cppOutputDir       = new List <string>();
                            var cppHeaderOutputDir = new List <string>();
                            if (cpp)
                            {
                                var waitEvent = new ManualResetEvent(false);
                                dispatcher.BeginInvoke(new Action(() =>
                                {
                                    foreach (EnvDTE.Configuration configuration in dteProject.ConfigurationManager)
                                    {
                                        cppOutputDir.Add(Package.Instance.VCUtil.Evaluate(configuration, outputDirUnevaluated));
                                        if (string.IsNullOrEmpty(headerOutputDirUnevaluated))
                                        {
                                            cppHeaderOutputDir.Add(Package.Instance.VCUtil.Evaluate(configuration, outputDirUnevaluated));
                                        }
                                        else
                                        {
                                            cppHeaderOutputDir.Add(Package.Instance.VCUtil.Evaluate(configuration, headerOutputDirUnevaluated));
                                        }
                                    }
                                    waitEvent.Set();
                                }));
                                waitEvent.WaitOne();
                            }
                            else
                            {
                                foreach (VSLangProj80.Reference3 r in dteProject.GetProjectRererences())
                                {
                                    if (Package.AssemblyNames.Contains(r.Name))
                                    {
                                        project.UpdateProject((MSProject msproject) =>
                                        {
                                            var item = msproject.AllEvaluatedItems.FirstOrDefault(referenceItem =>
                                                                                                  referenceItem.ItemType.Equals("Reference") &&
                                                                                                  referenceItem.EvaluatedInclude.Split(",".ToCharArray()).ElementAt(0).Equals(r.Name));
                                            if (item != null)
                                            {
                                                if (item.HasMetadata("HintPath"))
                                                {
                                                    var hintPath = item.GetMetadata("HintPath").UnevaluatedValue;
                                                    if (hintPath.Contains("$(IceAssembliesDir)"))
                                                    {
                                                        hintPath = hintPath.Replace("$(IceAssembliesDir)",
                                                                                    FileUtil.RelativePath(Path.GetDirectoryName(r.ContainingProject.FullName), assemblyDir));
                                                        //
                                                        // If the HintPath points to the NuGet zeroc.ice.net package we upgrade it to not
                                                        // use IceAssembliesDir otherwise we remove it
                                                        if (hintPath.Contains("packages\\zeroc.ice.net"))
                                                        {
                                                            item.SetMetadataValue("HintPath", hintPath);
                                                        }
                                                        else
                                                        {
                                                            item.RemoveMetadata("HintPath");
                                                        }
                                                    }
                                                }
                                            }
                                        });
                                    }
                                }
                            }

                            project.UpdateProject((MSProject msproject) =>
                            {
                                MSBuildUtils.UpgradeProjectImports(msproject);
                                MSBuildUtils.UpgradeProjectProperties(msproject, cpp);
                                MSBuildUtils.RemoveIceBuilderFromProject(msproject, true);
                                MSBuildUtils.UpgradeProjectItems(msproject);
                                MSBuildUtils.UpgradeCSharpGeneratedItems(msproject, outputDir);
                                foreach (var d in cppOutputDir)
                                {
                                    MSBuildUtils.UpgradeGeneratedItems(msproject, d, sourceExt, "ClCompile");
                                }

                                foreach (var d in cppHeaderOutputDir)
                                {
                                    MSBuildUtils.UpgradeGeneratedItems(msproject, d, headerExt, "ClInclude");
                                }

                                var propertyGroup = msproject.Xml.PropertyGroups.FirstOrDefault(group => group.Label.Equals("IceBuilder"));
                                if (propertyGroup != null)
                                {
                                    propertyGroup.Parent.RemoveChild(propertyGroup);
                                }

                                if (cpp)
                                {
                                    propertyGroup       = msproject.Xml.AddPropertyGroup();
                                    propertyGroup.Label = "IceBuilder";
                                    propertyGroup.AddProperty("IceCppMapping", "cpp98");
                                }
                            });

                            builder.ReloadProject(project);
                        }
                    }
                    dispatcher.BeginInvoke(new Action(() => progressCallback.Finished()));
                }
                catch (Exception ex)
                {
                    dispatcher.BeginInvoke(new Action(() => progressCallback.Canceled = true));
                    Package.UnexpectedExceptionWarning(ex);
                }
            });

            t.Start();
        }
        public static void Upgrade(Dictionary <string, IVsProject> projects, UpgradeProgressCallback progressCallback)
        {
            Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
            Thread     t          = new Thread(() =>
            {
                var NuGet   = Package.Instance.NuGet;
                var DTE     = Package.Instance.DTE;
                var builder = Package.Instance;
                int i       = 0;
                int total   = projects.Count;
                foreach (var entry in projects)
                {
                    var project    = entry.Value;
                    var dteProject = project.GetDTEProject();
                    var name       = entry.Key;
                    i++;
                    if (progressCallback.Canceled)
                    {
                        break;
                    }

                    dispatcher.Invoke(
                        new Action(() =>
                    {
                        progressCallback.ReportProgress(name, i);
                    }));

                    NuGet.Restore(dteProject);
                    if (!NuGet.IsPackageInstalled(dteProject, Package.NuGetBuilderPackageId))
                    {
                        DTE.StatusBar.Text = string.Format("Installing NuGet package {0} in project {1}",
                                                           Package.NuGetBuilderPackageId, name);
                        NuGet.InstallLatestPackage(dteProject, Package.NuGetBuilderPackageId);
                    }

                    IceBuilderProjectType projectType = DTEUtil.IsIceBuilderEnabled(project);
                    if (projectType != IceBuilderProjectType.None)
                    {
                        bool cpp           = projectType == IceBuilderProjectType.CppProjectType;
                        DTE.StatusBar.Text = string.Format("Upgrading project {0} Ice Builder settings", project.GetDTEProject().UniqueName);
                        var msproject      = project.GetMSBuildProject();
                        var fullPath       = ProjectUtil.GetProjectFullPath(project);
                        var assemblyDir    = ProjectUtil.GetEvaluatedProperty(project, "IceAssembliesDir");
                        if (projectType == IceBuilderProjectType.CsharpProjectType)
                        {
                            foreach (VSLangProj80.Reference3 r in dteProject.GetProjectRererences())
                            {
                                if (Package.AssemblyNames.Contains(r.Name))
                                {
                                    var item = msproject.AllEvaluatedItems.FirstOrDefault(referenceItem =>
                                                                                          referenceItem.ItemType.Equals("Reference") &&
                                                                                          referenceItem.EvaluatedInclude.Split(",".ToCharArray()).ElementAt(0).Equals(r.Name));
                                    if (item != null)
                                    {
                                        if (item.HasMetadata("HintPath"))
                                        {
                                            var hintPath = item.GetMetadata("HintPath").UnevaluatedValue;
                                            if (hintPath.Contains("$(IceAssembliesDir)"))
                                            {
                                                hintPath = hintPath.Replace("$(IceAssembliesDir)",
                                                                            FileUtil.RelativePath(Path.GetDirectoryName(r.ContainingProject.FullName), assemblyDir));
                                                //
                                                // If the HintPath points to the NuGet zeroc.ice.net package we upgrade it to not
                                                // use IceAssembliesDir otherwise we remove it
                                                if (hintPath.Contains("packages\\zeroc.ice.net"))
                                                {
                                                    item.SetMetadataValue("HintPath", hintPath);
                                                }
                                                else
                                                {
                                                    item.RemoveMetadata("HintPath");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        bool modified = MSBuildUtils.UpgradeProjectImports(msproject);
                        modified      = MSBuildUtils.UpgradeProjectProperties(msproject, cpp) || modified;
                        modified      = MSBuildUtils.RemoveIceBuilderFromProject(msproject, true) || modified;
                        modified      = MSBuildUtils.UpgradeProjectItems(msproject, cpp) || modified;

                        if (modified)
                        {
                            builder.SaveProject(project);
                        }
                    }
                }
                dispatcher.BeginInvoke(new Action(() => progressCallback.Finished()));
            });

            t.Start();
        }