Ejemplo n.º 1
0
        private async Task <bool> CheckPackageManagementFormat(INuGetUI uiService, CancellationToken token)
        {
#if VS14
            // don't show this dialog for VS 2015
            return(await Task.FromResult(true));
#else
            var potentialProjects = new List <NuGetProject>();

            // check if project is packages.config and it's dte project instance can also be converted to VSProject4.
            // otherwise don't show format selector dialog for this project
            var msBuildProjects = uiService.Projects.Where(project =>
                                                           project is MSBuildNuGetProject &&
                                                           (project as MSBuildNuGetProject).MSBuildNuGetProjectSystem.VSProject4 != null);

            // get all packages.config based projects with no installed packages
            foreach (var project in msBuildProjects)
            {
                if (!(await project.GetInstalledPackagesAsync(token)).Any())
                {
                    potentialProjects.Add(project);
                }
            }

            // only show this dialog if there are any new project(s) with no installed packages.
            if (potentialProjects.Count > 0)
            {
                var packageManagementFormat = new PackageManagementFormat(uiService.Settings);
                if (!packageManagementFormat.Enabled)
                {
                    // user disabled this prompt either through Tools->options or previous interaction of this dialog.
                    // now check for default package format, if its set to PackageReference then update the project.
                    if (packageManagementFormat.SelectedPackageManagementFormat == 1)
                    {
                        await uiService.UpdateNuGetProjectToPackageRef(potentialProjects);
                    }

                    return(true);
                }

                packageManagementFormat.ProjectNames = potentialProjects
                                                       .Select(project => project.GetMetadata <string>(NuGetProjectMetadataKeys.Name))
                                                       .OrderBy(name => name, StringComparer.OrdinalIgnoreCase).ToList();

                // show dialog for package format selector
                var result = uiService.PromptForPackageManagementFormat(packageManagementFormat);

                // update nuget projects if user selected PackageReference option
                if (result && packageManagementFormat.SelectedPackageManagementFormat == 1)
                {
                    await uiService.UpdateNuGetProjectToPackageRef(potentialProjects);
                }
                return(result);
            }

            return(true);
#endif
        }
Ejemplo n.º 2
0
        private async Task <bool> CheckPackageManagementFormat(INuGetUI uiService, CancellationToken token)
        {
            var potentialProjects = new List <NuGetProject>();

            // check if project suppports <PackageReference> items.
            // otherwise don't show format selector dialog for this project
            var capableProjects = uiService
                                  .Projects
                                  .Where(project =>
                                         project.ProjectStyle == ProjectModel.ProjectStyle.PackagesConfig &&
                                         project.ProjectServices.Capabilities.SupportsPackageReferences);

            // get all packages.config based projects with no installed packages
            foreach (var project in capableProjects)
            {
                var installedPackages = await project.GetInstalledPackagesAsync(token);

                if (!installedPackages.Any())
                {
                    potentialProjects.Add(project);
                }
            }

            // only show this dialog if there are any new project(s) with no installed packages.
            if (potentialProjects.Count > 0)
            {
                var packageManagementFormat = new PackageManagementFormat(uiService.Settings);
                if (!packageManagementFormat.Enabled)
                {
                    // user disabled this prompt either through Tools->options or previous interaction of this dialog.
                    // now check for default package format, if its set to PackageReference then update the project.
                    if (packageManagementFormat.SelectedPackageManagementFormat == 1)
                    {
                        await uiService.UpdateNuGetProjectToPackageRef(potentialProjects);
                    }

                    return(true);
                }

                packageManagementFormat.ProjectNames = potentialProjects
                                                       .Select(project => project.GetMetadata <string>(NuGetProjectMetadataKeys.Name))
                                                       .OrderBy(name => name, StringComparer.OrdinalIgnoreCase).ToList();

                // show dialog for package format selector
                var result = uiService.PromptForPackageManagementFormat(packageManagementFormat);

                // update nuget projects if user selected PackageReference option
                if (result && packageManagementFormat.SelectedPackageManagementFormat == 1)
                {
                    await uiService.UpdateNuGetProjectToPackageRef(potentialProjects);
                }
                return(result);
            }

            return(true);
        }