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(); }