int IVsSolutionEventsProjectUpgrade.OnAfterUpgradeProject(IVsHierarchy pHierarchy, uint fUpgradeFlag, string bstrCopyLocation, SYSTEMTIME stUpgradeTime, IVsUpgradeLogger pLogger) { NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); Debug.Assert(pHierarchy != null); var upgradedProject = VsHierarchyUtility.GetProjectFromHierarchy(pHierarchy); var upgradedNuGetProject = await EnvDTEProjectUtility.GetNuGetProjectAsync(upgradedProject, _solutionManager); if (ProjectRetargetingUtility.IsProjectRetargetable(upgradedNuGetProject)) { var packagesToBeReinstalled = await ProjectRetargetingUtility.GetPackagesToBeReinstalled(upgradedNuGetProject); if (packagesToBeReinstalled.Any()) { pLogger.LogMessage((int)__VSUL_ERRORLEVEL.VSUL_ERROR, upgradedProject.Name, upgradedProject.Name, string.Format(CultureInfo.CurrentCulture, Strings.ProjectUpgradeAndRetargetErrorMessage, string.Join(", ", packagesToBeReinstalled.Select(p => p.Id)))); } } }); return(VSConstants.S_OK); }
int IVsTrackProjectRetargetingEvents.OnRetargetingAfterChange(string projRef, IVsHierarchy pAfterChangeHier, string fromTargetFramework, string toTargetFramework) { NuGetProject retargetedProject = null; NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); _errorListProvider.Tasks.Clear(); var project = VsHierarchyUtility.GetProjectFromHierarchy(pAfterChangeHier); retargetedProject = await EnvDTEProjectUtility.GetNuGetProjectAsync(project, _solutionManager); if (ProjectRetargetingUtility.IsProjectRetargetable(retargetedProject)) { var packagesToBeReinstalled = await ProjectRetargetingUtility.GetPackagesToBeReinstalled(retargetedProject); if (packagesToBeReinstalled.Any()) { ShowRetargetingErrorTask(packagesToBeReinstalled.Select(p => p.Id), pAfterChangeHier, TaskErrorCategory.Error, TaskPriority.High); } // NuGet/Home#4833 Baseline // Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. #pragma warning disable CS4014 ProjectRetargetingUtility.MarkPackagesForReinstallation(retargetedProject, packagesToBeReinstalled); #pragma warning restore CS4014 } }); if (retargetedProject is LegacyPackageReferenceProject) { // trigger solution restore and don't wait for it to be complete and hold the UI thread System.Threading.Tasks.Task.Run(() => _solutionRestoreWorker.Value.ScheduleRestoreAsync(SolutionRestoreRequest.ByMenu(), CancellationToken.None)); } return(VSConstants.S_OK); }
public async Task <IVsProjectAdapter> CreateAdapterForFullyLoadedProjectAsync(IVsHierarchy hierarchy) { Assumes.Present(hierarchy); // Get services while we might be on background thread var vsSolution = await _vsSolution.GetValueAsync(); // switch to main thread and use services we know must be done on main thread. await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync(); var vsHierarchyItem = VsHierarchyItem.FromVsHierarchy(hierarchy); Func <IVsHierarchy, EnvDTE.Project> loadDteProject = hierarchy => VsHierarchyUtility.GetProjectFromHierarchy(hierarchy); var buildStorageProperty = vsHierarchyItem.VsHierarchy as IVsBuildPropertyStorage; var vsBuildProperties = new VsProjectBuildProperties( new Lazy <EnvDTE.Project>(() => loadDteProject(hierarchy)), buildStorageProperty, _threadingService); var fullProjectPath = VsHierarchyUtility.GetProjectPath(hierarchy); var projectNames = await ProjectNames.FromIVsSolution2(fullProjectPath, (IVsSolution2)vsSolution, hierarchy, CancellationToken.None); return(new VsProjectAdapter( vsHierarchyItem, projectNames, fullProjectPath, loadDteProject, vsBuildProperties, _threadingService)); }