Exemple #1
0
        int IVsTrackBatchRetargetingEvents.OnBatchRetargetingEnd()
        {
            NuGetProject nuGetProject = null;

            NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                _errorListProvider.Tasks.Clear();
                if (_platformRetargetingProject != null)
                {
                    try
                    {
                        var project = _dte.Solution.Item(_platformRetargetingProject);

                        if (project != null)
                        {
                            nuGetProject = await EnvDTEProjectUtility.GetNuGetProjectAsync(project, _solutionManager);

                            if (ProjectRetargetingUtility.IsProjectRetargetable(nuGetProject))
                            {
                                var frameworkName = project.GetTargetFrameworkString();
                                if (NETCore451.Equals(frameworkName, StringComparison.OrdinalIgnoreCase) || Windows81.Equals(frameworkName, StringComparison.OrdinalIgnoreCase))
                                {
                                    var packagesToBeReinstalled = await ProjectRetargetingUtility.GetPackagesToBeReinstalled(nuGetProject);
                                    if (packagesToBeReinstalled.Count > 0)
                                    {
                                        // By asserting that NuGet is in use, we are also asserting that NuGet.VisualStudio.dll is already loaded
                                        // Hence, it is okay to call project.ToVsHierarchyAsync()
                                        Debug.Assert(await ProjectRetargetingUtility.IsNuGetInUseAsync(project));
                                        var projectHierarchy = await project.ToVsHierarchyAsync();
                                        ShowRetargetingErrorTask(packagesToBeReinstalled.Select(p => p.Id), projectHierarchy, 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(nuGetProject, packagesToBeReinstalled);
#pragma warning restore CS4014
                                }
                            }
                        }
                    }
                    catch (ArgumentException)
                    {
                        // If the solution does not contain a project named '_platformRetargetingProject', it will throw ArgumentException
                    }
                    _platformRetargetingProject = null;
                }
            });

            if (nuGetProject 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.ByUserCommand(ExplicitRestoreReason.ProjectRetargeting), CancellationToken.None));
            }

            return(VSConstants.S_OK);
        }
Exemple #2
0
        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.ByUserCommand(ExplicitRestoreReason.ProjectRetargeting), CancellationToken.None));
            }
            return(VSConstants.S_OK);
        }