private void ReinstallPackage(
            string id, IProjectManager projectManager,
            ReinstallInfo reinstallInfo,
            ActionResolver resolver)
        {
            // find the package version installed in this project
            IPackage existingPackage = projectManager.LocalRepository.FindPackage(id);

            if (existingPackage == null)
            {
                return;
            }

            bool packageExistInSource;

            if (!reinstallInfo.VersionsChecked.TryGetValue(existingPackage.Version, out packageExistInSource))
            {
                // version has not been checked, so check it here
                packageExistInSource = PackageManager.SourceRepository.Exists(id, existingPackage.Version);

                // mark the version as checked so that we don't have to check again if we
                // encounter another project with the same version.
                reinstallInfo.VersionsChecked[existingPackage.Version] = packageExistInSource;
            }

            if (packageExistInSource)
            {
                resolver.AddOperation(PackageAction.Uninstall, existingPackage, projectManager);

                var packageFromSource = PackageManager.SourceRepository.FindPackage(id, existingPackage.Version);
                resolver.AddOperation(PackageAction.Install, packageFromSource, projectManager);
            }
            else
            {
                Log(
                    MessageLevel.Warning,
                    VsResources.PackageRestoreSkipForProject,
                    existingPackage.GetFullName(),
                    projectManager.Project.ProjectName);
            }
        }
Пример #2
0
        private void ReinstallPackage(
            string id, IProjectManager projectManager, 
            ReinstallInfo reinstallInfo,
            ActionResolver resolver)
        {
            // find the package version installed in this project
            IPackage existingPackage = projectManager.LocalRepository.FindPackage(id);
            if (existingPackage == null)
            {
                return;
            }

            bool packageExistInSource;
            if (!reinstallInfo.VersionsChecked.TryGetValue(existingPackage.Version, out packageExistInSource))
            {
                // version has not been checked, so check it here
                packageExistInSource = PackageManager.SourceRepository.Exists(id, existingPackage.Version);

                // mark the version as checked so that we don't have to check again if we
                // encounter another project with the same version.
                reinstallInfo.VersionsChecked[existingPackage.Version] = packageExistInSource;
            }

            if (packageExistInSource)
            {
                resolver.AddOperation(PackageAction.Uninstall, existingPackage, projectManager);

                var packageFromSource = PackageManager.SourceRepository.FindPackage(id, existingPackage.Version);
                resolver.AddOperation(PackageAction.Install, packageFromSource, projectManager);
            }
            else
            {
                Log(
                    MessageLevel.Warning,
                    VsResources.PackageRestoreSkipForProject,
                    existingPackage.GetFullName(),
                    projectManager.Project.ProjectName);
            }
        }
        private void ReinstallOnePackage(string id, IEnumerable <IProjectManager> projectManagers)
        {
            List <Resolver.PackageAction> actions = new List <Resolver.PackageAction>();
            var projectNameSpecified = !String.IsNullOrEmpty(ProjectName);
            var oldPackage           = projectNameSpecified ?
                                       UpdateUtility.FindPackageToUpdate(
                id, version: null,
                packageManager: PackageManager,
                projectManager: projectManagers.First()) :
                                       UpdateUtility.FindPackageToUpdate(
                id, version: null,
                packageManager: PackageManager,
                projectManagers: projectManagers,
                logger: this);

            if (oldPackage.Item2 == null)
            {
                // we're reinstalling a solution level package
                Log(MessageLevel.Info, VsResources.ReinstallSolutionPackage, oldPackage.Item1);
                if (PackageManager.SourceRepository.Exists(oldPackage.Item1))
                {
                    var resolver = new ActionResolver()
                    {
                        ForceRemove = true
                    };
                    resolver.AddOperation(PackageAction.Uninstall, oldPackage.Item1, new NullProjectManager(PackageManager));

                    var packageFromSource = PackageManager.SourceRepository.FindPackage(
                        oldPackage.Item1.Id,
                        oldPackage.Item1.Version);
                    resolver.AddOperation(PackageAction.Install, packageFromSource, new NullProjectManager(PackageManager));
                    actions.AddRange(resolver.ResolveActions());
                }
                else
                {
                    Log(
                        MessageLevel.Warning,
                        VsResources.PackageRestoreSkipForSolution,
                        oldPackage.Item1.GetFullName());
                }
            }
            else
            {
                var reinstallInfo = new ReinstallInfo(Enumerable.Empty <VirtualProjectManager>());
                var resolver      = new ActionResolver()
                {
                    ForceRemove = true
                };
                foreach (var projectManager in projectManagers)
                {
                    ReinstallPackage(id, projectManager, reinstallInfo, resolver);
                }

                actions.AddRange(resolver.ResolveActions());
            }

            if (WhatIf)
            {
                foreach (var action in actions)
                {
                    Log(MessageLevel.Info, Resources.Log_OperationWhatIf, action);
                }

                return;
            }

            var executor = new ActionExecutor()
            {
                Logger = this,
                PackageOperationEventListener  = this,
                CatchProjectOperationException = true
            };

            executor.Execute(actions);
        }
Пример #4
0
        private void ReinstallOnePackage(string id, IEnumerable<IProjectManager> projectManagers)
        {
            List<Resolver.PackageAction> actions = new List<Resolver.PackageAction>();
            var projectNameSpecified = !String.IsNullOrEmpty(ProjectName);
            var oldPackage = projectNameSpecified ?
                UpdateUtility.FindPackageToUpdate(
                    id, version: null, 
                    packageManager: PackageManager,
                    projectManager: projectManagers.First()) :
                UpdateUtility.FindPackageToUpdate(
                    id, version: null, 
                    packageManager: PackageManager,
                    projectManagers: projectManagers, 
                    logger: this);

            if (oldPackage.Item2 == null)
            {
                // we're reinstalling a solution level package
                Log(MessageLevel.Info, VsResources.ReinstallSolutionPackage, oldPackage.Item1);
                if (PackageManager.SourceRepository.Exists(oldPackage.Item1))
                {
                    var resolver = new ActionResolver()
                    {
                        ForceRemove = true
                    };
                    resolver.AddOperation(PackageAction.Uninstall, oldPackage.Item1, new NullProjectManager(PackageManager));

                    var packageFromSource = PackageManager.SourceRepository.FindPackage(
                        oldPackage.Item1.Id,
                        oldPackage.Item1.Version);
                    resolver.AddOperation(PackageAction.Install, packageFromSource, new NullProjectManager(PackageManager));
                    actions.AddRange(resolver.ResolveActions());
                }
                else
                {
                    Log(
                        MessageLevel.Warning,
                        VsResources.PackageRestoreSkipForSolution,
                        oldPackage.Item1.GetFullName());
                }
            }
            else
            {
                var reinstallInfo = new ReinstallInfo(Enumerable.Empty<VirtualProjectManager>());
                var resolver = new ActionResolver()
                {
                    ForceRemove = true
                };
                foreach (var projectManager in projectManagers)
                {
                    ReinstallPackage(id, projectManager, reinstallInfo, resolver);
                }

                actions.AddRange(resolver.ResolveActions());
            }

            if (WhatIf)
            {
                foreach (var action in actions)
                {
                    Log(MessageLevel.Info, Resources.Log_OperationWhatIf, action);
                }

                return;
            }

            var executor = new ActionExecutor()
            {
                Logger = this,
                PackageOperationEventListener = this,
                CatchProjectOperationException = true
            };
            executor.Execute(actions);
        }