Inheritance: IVsPackageMetadata
        public IEnumerable<IVsPackageMetadata> GetInstalledPackages()
        {
            List<IVsPackageMetadata> packages = new List<IVsPackageMetadata>();

            // Debug.Assert(_solutionManager.SolutionDirectory != null, "SolutionDir is null");

            // Calls may occur in the template wizard before the solution is actually created, in that case return no projects
            if (_solutionManager != null && !String.IsNullOrEmpty(_solutionManager.SolutionDirectory))
            {
                InitializePackageManagerAndPackageFolderPath();

                foreach (var project in _solutionManager.GetNuGetProjects())
                {
                    var task = System.Threading.Tasks.Task.Run(async () => await project.GetInstalledPackagesAsync(CancellationToken.None));
                    task.Wait();

                    foreach (var package in task.Result)
                    {
                        // find packages using the solution level packages folder
                        string installPath = _packageManager.PackagesFolderNuGetProject.GetInstalledPath(package.PackageIdentity);

                        var metadata = new VsPackageMetadata(package.PackageIdentity, installPath);
                        packages.Add(metadata);
                    }
                }
            }

            return packages;
        }
Example #2
0
        public IEnumerable <IVsPackageMetadata> GetInstalledPackages()
        {
            var packages = new HashSet <IVsPackageMetadata>(new VsPackageMetadataComparer());

            return(NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                // Calls may occur in the template wizard before the solution is actually created,
                // in that case return no projects
                if (_solutionManager != null &&
                    !string.IsNullOrEmpty(_solutionManager.SolutionDirectory))
                {
                    //switch to background thread
                    await TaskScheduler.Default;

                    NuGetPackageManager nuGetPackageManager = CreateNuGetPackageManager();

                    foreach (var project in (await _solutionManager.GetNuGetProjectsAsync()))
                    {
                        FallbackPackagePathResolver pathResolver = null;
                        var buildIntegratedProject = project as BuildIntegratedNuGetProject;
                        if (buildIntegratedProject != null)
                        {
                            pathResolver = await GetPackagesPathResolverAsync(buildIntegratedProject);
                        }

                        var installedPackages = await project.GetInstalledPackagesAsync(CancellationToken.None);

                        foreach (var package in installedPackages)
                        {
                            var identity = package.PackageIdentity;

                            if (!identity.HasVersion)
                            {
                                // Currently we are not supporting floating versions
                                // because of that we will skip this package
                                continue;
                            }

                            // find packages using the solution level packages folder
                            string installPath;
                            if (buildIntegratedProject != null)
                            {
                                installPath = pathResolver.GetPackageDirectory(identity.Id, identity.Version);
                            }
                            else
                            {
                                installPath = nuGetPackageManager
                                              .PackagesFolderNuGetProject
                                              .GetInstalledPath(identity);
                            }

                            var metadata = new VsPackageMetadata(package.PackageIdentity, installPath);

                            packages.Add(metadata);
                        }
                    }
                }

                return packages;
            }));
        }
Example #3
0
        public IEnumerable <IVsPackageMetadata> GetInstalledPackages(Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            return(NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                var packages = new List <IVsPackageMetadata>();

                if (_solutionManager != null &&
                    !string.IsNullOrEmpty(_solutionManager.SolutionDirectory))
                {
                    //switch to background thread
                    await TaskScheduler.Default;

                    NuGetPackageManager nuGetPackageManager = CreateNuGetPackageManager();

                    var projectContext = new VSAPIProjectContext
                    {
                        PackageExtractionContext = new PackageExtractionContext(
                            PackageSaveMode.Defaultv2,
                            PackageExtractionBehavior.XmlDocFileSaveMode,
                            ClientPolicyContext.GetClientPolicy(_settings, NullLogger.Instance),
                            NullLogger.Instance)
                    };

                    var nuGetProject = await _solutionManager.GetOrCreateProjectAsync(
                        project,
                        projectContext);

                    if (nuGetProject != null)
                    {
                        FallbackPackagePathResolver pathResolver = null;
                        var buildIntegratedProject = nuGetProject as BuildIntegratedNuGetProject;
                        if (buildIntegratedProject != null)
                        {
                            pathResolver = await GetPackagesPathResolverAsync(buildIntegratedProject);
                        }

                        var installedPackages = await nuGetProject.GetInstalledPackagesAsync(CancellationToken.None);

                        foreach (var package in installedPackages)
                        {
                            if (!package.PackageIdentity.HasVersion)
                            {
                                // Currently we are not supporting floating versions
                                // because of that we will skip this package so that it doesn't throw ArgumentNullException
                                continue;
                            }

                            string installPath;
                            if (buildIntegratedProject != null)
                            {
                                installPath = pathResolver.GetPackageDirectory(package.PackageIdentity.Id, package.PackageIdentity.Version);
                            }
                            else
                            {
                                // Get the install path for package
                                installPath = nuGetPackageManager.PackagesFolderNuGetProject.GetInstalledPath(
                                    package.PackageIdentity);

                                if (!string.IsNullOrEmpty(installPath))
                                {
                                    // normalize the path and take the dir if the nupkg path was given
                                    var dir = new DirectoryInfo(installPath);
                                    installPath = dir.FullName;
                                }
                            }

                            var metadata = new VsPackageMetadata(package.PackageIdentity, installPath);
                            packages.Add(metadata);
                        }
                    }
                }

                return packages;
            }));
        }
Example #4
0
        public IEnumerable <IVsPackageMetadata> GetInstalledPackages(Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            return(NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                var packages = new List <IVsPackageMetadata>();

                if (_solutionManager != null &&
                    !string.IsNullOrEmpty(_solutionManager.SolutionDirectory))
                {
                    InitializePackageManagerAndPackageFolderPath();

                    var nuGetProject = await _solutionManager.GetOrCreateProjectAsync(
                        project,
                        new VSAPIProjectContext());

                    if (nuGetProject != null)
                    {
                        FallbackPackagePathResolver pathResolver = null;
                        var buildIntegratedProject = nuGetProject as BuildIntegratedNuGetProject;
                        if (buildIntegratedProject != null)
                        {
                            pathResolver = await GetPackagesPathResolverAsync(buildIntegratedProject);
                        }

                        var installedPackages = await nuGetProject.GetInstalledPackagesAsync(CancellationToken.None);

                        foreach (var package in installedPackages)
                        {
                            string installPath;
                            if (buildIntegratedProject != null)
                            {
                                installPath = pathResolver.GetPackageDirectory(package.PackageIdentity.Id, package.PackageIdentity.Version);
                            }
                            else
                            {
                                // Get the install path for package
                                installPath = _packageManager.PackagesFolderNuGetProject.GetInstalledPath(
                                    package.PackageIdentity);

                                if (!string.IsNullOrEmpty(installPath))
                                {
                                    // normalize the path and take the dir if the nupkg path was given
                                    var dir = new DirectoryInfo(installPath);
                                    installPath = dir.FullName;
                                }
                            }

                            var metadata = new VsPackageMetadata(package.PackageIdentity, installPath);
                            packages.Add(metadata);
                        }
                    }
                }

                return packages;
            }));
        }
        public IEnumerable<IVsPackageMetadata> GetInstalledPackages(Project project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            List<IVsPackageMetadata> packages = new List<IVsPackageMetadata>();

            // Debug.Assert(_solutionManager.SolutionDirectory != null, "SolutionDir is null");

            if (_solutionManager != null && !String.IsNullOrEmpty(_solutionManager.SolutionDirectory))
            {
                InitializePackageManagerAndPackageFolderPath();

                var nuGetProject = PackageManagementHelpers.GetProject(_solutionManager, project, new VSAPIProjectContext());
                var task = System.Threading.Tasks.Task.Run(async () => await nuGetProject.GetInstalledPackagesAsync(CancellationToken.None));
                task.Wait();

                foreach (var package in task.Result)
                {
                    // Get the install path for package
                    string installPath = _packageManager.PackagesFolderNuGetProject.GetInstalledPath(package.PackageIdentity);

                    if (!String.IsNullOrEmpty(installPath))
                    {
                        // normalize the path and take the dir if the nupkg path was given
                        var dir = new DirectoryInfo(installPath);
                        installPath = dir.FullName;
                    }

                    var metadata = new VsPackageMetadata(package.PackageIdentity, installPath);
                    packages.Add(metadata);
                }
            }

            return packages;
        }