private string GetPackageInstalledPath(PackageIdentity packageIdentity)
        {
            string effectiveGlobalPackagesFolder = null;

            if (!string.IsNullOrEmpty(SolutionDirectory))
            {
                // Package not found in packages folder
                effectiveGlobalPackagesFolder = BuildIntegratedProjectUtility.GetEffectiveGlobalPackagesFolder(
                    SolutionDirectory,
                    Settings);
            }
            else
            {
                // No solution available. Use default global packages folder
                effectiveGlobalPackagesFolder = SettingsUtility.GetGlobalPackagesFolder(Settings);
            }

            var versionFolderPathResolver = new VersionFolderPathResolver(effectiveGlobalPackagesFolder);
            var hashPath = versionFolderPathResolver.GetHashPath(packageIdentity.Id, packageIdentity.Version);

            if (File.Exists(hashPath))
            {
                var packageInstallPath = Path.GetDirectoryName(hashPath);
                return(packageInstallPath);
            }

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

            return(ThreadHelper.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))
                {
                    InitializePackageManagerAndPackageFolderPath();

                    var effectiveGlobalPackagesFolder =
                        BuildIntegratedProjectUtility.GetEffectiveGlobalPackagesFolder(
                            _solutionManager.SolutionDirectory,
                            _settings);

                    foreach (var project in _solutionManager.GetNuGetProjects())
                    {
                        var installedPackages = await project.GetInstalledPackagesAsync(CancellationToken.None);
                        var buildIntegratedProject = project as BuildIntegratedNuGetProject;

                        foreach (var package in installedPackages)
                        {
                            if (!package.PackageIdentity.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 = BuildIntegratedProjectUtility.GetPackagePathFromGlobalSource(
                                    effectiveGlobalPackagesFolder,
                                    package.PackageIdentity);
                            }
                            else
                            {
                                installPath = _packageManager.PackagesFolderNuGetProject.GetInstalledPath(
                                    package.PackageIdentity);
                            }

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

                return packages;
            }));
        }
        public MonoDevelopBuildIntegratedRestorer(
            ISourceRepositoryProvider repositoryProvider,
            ISettings settings,
            string solutionDirectory)
        {
            sourceRepositories = repositoryProvider.GetRepositories().ToList();

            packageManagementEvents = PackageManagementServices.PackageManagementEvents;

            packagesFolder = BuildIntegratedProjectUtility.GetEffectiveGlobalPackagesFolder(
                solutionDirectory,
                settings);

            context = CreateRestoreContext();
        }
示例#4
0
        public static FilePath GetPackagesFolderPath(this NuGetProject project, IMonoDevelopSolutionManager solutionManager)
        {
            if (project is BuildIntegratedProjectSystem)
            {
                string globalPackagesPath = BuildIntegratedProjectUtility.GetEffectiveGlobalPackagesFolder(
                    solutionManager.SolutionDirectory,
                    solutionManager.Settings);

                return(new FilePath(globalPackagesPath).FullPath);
            }

            string path = PackagesFolderPathUtility.GetPackagesFolderPath(solutionManager, solutionManager.Settings);

            return(new FilePath(path).FullPath);
        }
        private async Task BuildIntegratedProjectRestoreAsync(
            BuildIntegratedNuGetProject project,
            string solutionDirectory,
            List <SourceRepository> enabledSources,
            ExternalProjectReferenceContext context,
            RestoreCommandProvidersCache providerCache,
            CancellationToken token)
        {
            // Go off the UI thread to perform I/O operations
            await TaskScheduler.Default;

            var projectName = NuGetProject.GetUniqueNameOrName(project);

            var effectiveGlobalPackagesFolder = BuildIntegratedProjectUtility.GetEffectiveGlobalPackagesFolder(
                SolutionManager?.SolutionDirectory,
                Settings);

            using (var cacheContext = new SourceCacheContext())
            {
                providerCache.GetOrCreate(effectiveGlobalPackagesFolder,
                                          enabledSources,
                                          cacheContext,
                                          context.Logger);

                // Pass down the CancellationToken from the dialog
                var restoreResult = await BuildIntegratedRestoreUtility.RestoreAsync(project,
                                                                                     context,
                                                                                     enabledSources,
                                                                                     effectiveGlobalPackagesFolder,
                                                                                     token);

                if (!restoreResult.Success)
                {
                    // Mark this as having errors
                    _hasErrors = true;

                    // Invalidate cached results for the project. This will cause it to restore the next time.
                    _buildIntegratedCache.Remove(projectName);
                    await BuildIntegratedProjectReportErrorAsync(projectName, restoreResult, token);
                }
            }
        }
        /// <summary>
        /// Get the view of installed packages. Use for Get-Package command.
        /// </summary>
        internal static List <PowerShellInstalledPackage> GetPowerShellPackageView(Dictionary <NuGetProject, IEnumerable <Packaging.PackageReference> > dictionary,
                                                                                   ISolutionManager SolutionManager, Configuration.ISettings settings)
        {
            var views = new List <PowerShellInstalledPackage>();

            foreach (var entry in dictionary)
            {
                var nugetProject = entry.Key;

                string             packageFolder        = null;
                FolderNuGetProject packageFolderProject = null;

                if (nugetProject is BuildIntegratedNuGetProject)
                {
                    packageFolder = BuildIntegratedProjectUtility.GetEffectiveGlobalPackagesFolder(SolutionManager.SolutionDirectory, settings);
                }
                else
                {
                    var project = nugetProject as MSBuildNuGetProject;

                    if (project != null)
                    {
                        packageFolderProject = project.FolderNuGetProject;
                    }
                }

                // entry.Value is an empty list if no packages are installed
                foreach (var package in entry.Value)
                {
                    string installPackagePath = null;
                    string licenseUrl         = null;

                    if (packageFolder != null)
                    {
                        var defaultPackagePathResolver = new VersionFolderPathResolver(packageFolder, normalizePackageId: false);
                        installPackagePath = defaultPackagePathResolver.GetPackageFilePath(package.PackageIdentity.Id, package.PackageIdentity.Version);
                    }
                    else if (packageFolderProject != null)
                    {
                        installPackagePath = packageFolderProject.GetInstalledPackageFilePath(package.PackageIdentity);
                    }

                    using (var reader = GetPackageReader(installPackagePath))
                    {
                        var nuspecReader = new NuspecReader(reader.GetNuspec());
                        licenseUrl = nuspecReader.GetLicenseUrl();
                    }


                    var view = new PowerShellInstalledPackage()
                    {
                        Id = package.PackageIdentity.Id,
                        AsyncLazyVersions = new AsyncLazy <IEnumerable <NuGetVersion> >(() => Task.FromResult <IEnumerable <NuGetVersion> >(new[] { package.PackageIdentity.Version }), NuGetUIThreadHelper.JoinableTaskFactory),
                        ProjectName       = entry.Key.GetMetadata <string>(NuGetProjectMetadataKeys.Name),
                        LicenseUrl        = licenseUrl
                    };

                    views.Add(view);
                }
            }

            return(views);
        }