protected override void RemoveDependencies(Project proj, IVsPackageInstallerServices installerServices, IVsPackageUninstaller installer)
 {
     // AMF.NetCoreApiExplorer
     if (installerServices.IsPackageInstalled(proj, RamlNetCoreApiExplorerPackageId))
     {
         installer.UninstallPackage(proj, RamlNetCoreApiExplorerPackageId, false);
     }
 }
Esempio n. 2
0
        /// <inheritdoc/>
        public override void Execute(Project project)
        {
            var componentModel = (IComponentModel)this.Package.GetService(typeof(SComponentModel));
            IVsPackageUninstaller packageUninstaller = componentModel.GetService <IVsPackageUninstaller>();

            packageUninstaller.UninstallPackage(project, SlowCheetahNuGetManager.OldPackageName, true);

            this.Successor.Execute(project);
        }
        public static void UninstallPackageApi(string id, bool dependency)
        {
            EnvDTE.DTE            dte         = ServiceLocator.GetInstance <EnvDTE.DTE>();
            IVsPackageUninstaller uninstaller = ServiceLocator.GetInstance <IVsPackageUninstaller>();

            foreach (EnvDTE.Project project in dte.Solution.Projects)
            {
                uninstaller.UninstallPackage(project, id, dependency);
                return;
            }
        }
Esempio n. 4
0
        private void Execute(object sender, EventArgs e)
        {
            ProjectItem item = VsHelpers.DTE.SelectedItems.Item(1).ProjectItem;

            try
            {
                var dependencies = Dependencies.FromConfigFile(item.FileNames[1]);
                IEnumerable <string> packageIds = dependencies.Providers.Select(p => p.NuGetPackageId).Distinct();

                if (!_isPackageInstalled)
                {
                    if (!UserWantsToInstall())
                    {
                        return;
                    }

                    System.Threading.Tasks.Task.Run(() =>
                    {
                        Logger.LogEvent("Installing NuGet package containing MSBuild target...", LogLevel.Status);

                        foreach (string packageId in packageIds)
                        {
                            IVsPackageInstaller2 installer = _componentModel.GetService <IVsPackageInstaller2>();
                            installer.InstallLatestPackage(null, item.ContainingProject, packageId, true, false);
                        }

                        Telemetry.TrackUserTask("InstallNugetPackage");
                        Logger.LogEvent("NuGet package installed", LogLevel.Status);
                    });
                }
                else
                {
                    System.Threading.Tasks.Task.Run(() =>
                    {
                        Logger.LogEvent("Uninstalling NuGet package...", LogLevel.Status);

                        foreach (string packageId in packageIds)
                        {
                            IVsPackageUninstaller uninstaller = _componentModel.GetService <IVsPackageUninstaller>();
                            uninstaller.UninstallPackage(item.ContainingProject, packageId, false);
                        }

                        Telemetry.TrackUserTask("UninstallNugetPackage");
                        Logger.LogEvent("NuGet package uninstalled", LogLevel.Status);
                    });
                }
            }
            catch (Exception ex)
            {
                Telemetry.TrackException(nameof(RestoreOnBuildCommand), ex);
                Logger.LogEvent("Error installing NuGet package", LogLevel.Status);
            }
        }
        private void UpdateSlowCheetah(Project project)
        {
            // This is done on the UI thread because changes are made to the project file,
            // causing it to be reloaded. To avoid conflicts with NuGet installation,
            // the update is done sequentially
            if (this.HasUserAcceptedWarningMessage(Resources.Resources.NugetUpdate_Title, Resources.Resources.NugetUpdate_Text))
            {
                // Creates dialog informing the user to wait for the installation to finish
                IVsThreadedWaitDialogFactory twdFactory = this.package.GetService(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory;
                IVsThreadedWaitDialog2       dialog     = null;
                twdFactory?.CreateInstance(out dialog);

                string title = Resources.Resources.NugetUpdate_WaitTitle;
                string text  = Resources.Resources.NugetUpdate_WaitText;
                dialog?.StartWaitDialog(title, text, null, null, null, 0, false, true);
                try
                {
                    // Installs the latest version of the SlowCheetah NuGet package
                    var componentModel = (IComponentModel)this.package.GetService(typeof(SComponentModel));
                    if (this.IsSlowCheetahInstalled(project))
                    {
                        IVsPackageUninstaller packageUninstaller = componentModel.GetService <IVsPackageUninstaller>();
                        packageUninstaller.UninstallPackage(project, PackageName, true);
                    }

                    IVsPackageInstaller2 packageInstaller = componentModel.GetService <IVsPackageInstaller2>();
                    packageInstaller.InstallLatestPackage(null, project, PackageName, false, false);

                    project.Save();
                    ProjectRootElement projectRoot = ProjectRootElement.Open(project.FullName);
                    foreach (ProjectPropertyGroupElement propertyGroup in projectRoot.PropertyGroups.Where(pg => pg.Label.Equals("SlowCheetah")))
                    {
                        projectRoot.RemoveChild(propertyGroup);
                    }

                    foreach (ProjectImportElement import in projectRoot.Imports.Where(i => i.Label == "SlowCheetah" || i.Project == "$(SlowCheetahTargets)"))
                    {
                        projectRoot.RemoveChild(import);
                    }

                    projectRoot.Save();
                }
                finally
                {
                    // Closes the wait dialog. If the dialog failed, does nothing
                    int canceled;
                    dialog?.EndWaitDialog(out canceled);
                }
            }
        }
Esempio n. 6
0
        private void UninstallPackageNoForce(object sender, EventArgs e)
        {
            EnvDTE.DTE            dte         = ServiceLocator.GetInstance <EnvDTE.DTE>();
            IVsPackageInstaller   services    = ServiceLocator.GetInstance <IVsPackageInstaller>();
            IVsPackageUninstaller uninstaller = ServiceLocator.GetInstance <IVsPackageUninstaller>();

            foreach (EnvDTE.Project project in dte.Solution.Projects)
            {
                _task = System.Threading.Tasks.Task.Run(() =>
                {
                    services.InstallPackage("https://api.nuget.org/v2/", project, "windowsazure.storage", "4.3.0", false);
                    uninstaller.UninstallPackage(project, "newtonsoft.json", true);
                });
                return;
            }
        }
        public static void UnInstallPackage(DTE dte, IVsPackageUninstaller uninstaller, Project project, string package)
        {
            try
            {
                StatusBar.SetStatusBarValue(dte, Resources.Resource.NuGetPackageUninstallingStatusBarMessage + ": " + package);

                uninstaller.UninstallPackage(project, package, true);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(Resources.Resource.NuGetPackageInstallFailureMessage + ": " + ex.Message);
            }
            finally
            {
                StatusBar.ClearStatusBarValue(dte);
            }
        }
        private void Execute(object sender, EventArgs e)
        {
            ProjectItem item = VsHelpers.DTE.SelectedItems.Item(1).ProjectItem;

            try
            {
                if (!_isPackageInstalled)
                {
                    if (!UserWantsToInstall())
                    {
                        return;
                    }

                    System.Threading.Tasks.Task.Run(() =>
                    {
                        Logger.LogEvent("Installing NuGet package containing MSBuild target...", LogLevel.Status);

                        IVsPackageInstaller2 installer = _componentModel.GetService <IVsPackageInstaller2>();
                        installer.InstallLatestPackage(null, item.ContainingProject, Constants.NuGetPackageId, true, false);

                        Telemetry.TrackUserTask("InstallNugetPackage");
                        Logger.LogEvent("NuGet package installed", LogLevel.Status);
                    });
                }
                else
                {
                    System.Threading.Tasks.Task.Run(() =>
                    {
                        Logger.LogEvent("Uninstalling NuGet package...", LogLevel.Status);

                        IVsPackageUninstaller uninstaller = _componentModel.GetService <IVsPackageUninstaller>();
                        uninstaller.UninstallPackage(item.ContainingProject, Constants.NuGetPackageId, false);

                        Telemetry.TrackUserTask("UninstallNugetPackage");
                        Logger.LogEvent("NuGet package uninstalled", LogLevel.Status);
                    });
                }
            }
            catch (Exception ex)
            {
                Telemetry.TrackException(nameof(RestoreOnBuildCommand), ex);
                Logger.LogEvent("Error installing NuGet package", LogLevel.Status);
            }
        }
Esempio n. 9
0
        public bool RemovePackage(string packageId)
        {
            if (!m_packageServices.IsPackageInstalled(m_project, packageId))
            {
                return(false);
            }


            var meta = m_packageServices.GetInstalledPackages(m_project).FirstOrDefault(p => p.Id == packageId);

            if (string.IsNullOrEmpty(meta?.InstallPath))
            {
                //
                // UinstallPackage() fails, with the following exception when the respective package is still
                // referenced by the project, but no longer present in the "packages"-folder.
                //
                // So in this case a rebuild of the project _and_ a restore of the (existing/old) NuGet
                // packages is required.
                //
                //  System.ArgumentException: Empty path name is not legal.
                //    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
                //    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
                //    at NuGet.ProjectManagement.MSBuildNuGetProject.<UninstallPackageAsync>d__36.MoveNext()
                //   ...
                //    at NuGet.VisualStudio.VsPackageUninstaller.UninstallPackage(Project project, String packageId, Boolean removeDependencies)
                //    at NUnitToMSTestPackage.Utilities.PackageHandler.RemovePackage(String packageId) in C:\Sources\Stuff\mine\NUnitToMSTest\NUnitToMSTestPackage\Utilities\PackageHandler.cs:line 87
                //    at NUnitToMSTestPackage.Commands.TransformProjectFilesCommand.RemoveNUnitPackages(Project selectedProject, StatusbarContext statusbar, Int32& complete, Int32 total) in C:\Sources\Stuff\mine\NUnitToMSTest\NUnitToMSTestPackage\Commands\TransformProjectFilesCommand.cs:line 186
                //    at NUnitToMSTestPackage.Commands.TransformProjectFilesCommand.<InvokeRefactoring>d__16.MoveNext() in C:\Sources\Stuff\mine\NUnitToMSTest\NUnitToMSTestPackage\Commands\TransformProjectFilesCommand.cs:line 147
                //
                string str = $"Could not remove package {packageId}, because it's InstallPath is not set. " +
                             "Possibly the package is no longer present in your \"packages\" folder. Packages can " +
                             "only be removed, if they are present there. You could revert what has changed, restore " +
                             "all existing/old packages and retry the conversion. Or you can manually remove the package " +
                             $"{packageId} from the project {m_project.Name}.";
                m_outputWindowPane?.OutputStringThreadSafe("Warning: " + str);
                ReportWarning?.Invoke(str);
                return(false);
            }

            m_uninstaller.UninstallPackage(m_project, packageId, true);
            return(true);
        }
Esempio n. 10
0
        /// <summary>
        /// Removes packages. Will do a couple of passes in case packages rely on each other
        /// </summary>
        /// <param name="project"></param>
        /// <param name="ids"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private bool RemovePackages(Project project, IEnumerable <string> ids, CancellationToken token)
        {
            var retryCount = new ConcurrentDictionary <string, int>(StringComparer.OrdinalIgnoreCase);
            var packages   = new Queue <string>(ids);
            var maxRetry   = packages.Count + 1;

            while (packages.Count > 0)
            {
                token.ThrowIfCancellationRequested();

                var package = packages.Dequeue();

                try
                {
                    _uninstaller.UninstallPackage(project, package, false);
                }
                catch (Exception e)
                {
                    if (e is InvalidOperationException)
                    {
                        Debug.WriteLine(e.Message);
                    }
                    else
                    {
                        Debug.WriteLine(e);
                    }

                    retryCount.AddOrUpdate(package, 1, (_, count) => count++);

                    if (retryCount[package] < maxRetry)
                    {
                        packages.Enqueue(package);
                    }
                }
            }

            return(!retryCount.Values.Any(v => v >= maxRetry));
        }
Esempio n. 11
0
 static void Realize(IVsPackageUninstaller uninstaller)
 {
     uninstaller.UninstallPackage(default(Project), default(string), default(bool));
 }
 public void UninstallPackage(EnvDTE.Project project, string packageId, bool removeDependencies)
 {
     _packageUninstaller.UninstallPackage(project, packageId, removeDependencies);
 }
Esempio n. 13
0
        private async Task ExecuteAsync(object sender, EventArgs e)
        {
            ProjectItem projectItem = await VsHelpers.GetSelectedItemAsync();

            Project project = await VsHelpers.GetProjectOfSelectedItemAsync();

            try
            {
                var dependencies = _dependenciesFactory.FromConfigFile(projectItem.FileNames[1]);
                IEnumerable <string> packageIds = dependencies.Providers
                                                  .Where(p => p.NuGetPackageId != null)
                                                  .Select(p => p.NuGetPackageId)
                                                  .Distinct();

                if (!_isPackageInstalled)
                {
                    if (!UserWantsToInstall())
                    {
                        return;
                    }

                    await Task.Run(() =>
                    {
                        Logger.LogEvent(Resources.Text.Nuget_InstallingPackage, LogLevel.Status);

                        try
                        {
                            foreach (string packageId in packageIds)
                            {
                                IVsPackageInstaller2 installer = _componentModel.GetService <IVsPackageInstaller2>();
                                installer.InstallLatestPackage(null, project, packageId, true, false);
                            }

                            Telemetry.TrackUserTask("Install-NugetPackage");
                            Logger.LogEvent(Resources.Text.Nuget_PackageInstalled, LogLevel.Status);
                        }
                        catch (Exception ex)
                        {
                            Telemetry.TrackException(nameof(RestoreOnBuildCommand), ex);
                            Logger.LogEvent(Resources.Text.Nuget_PackageFailedToInstall, LogLevel.Status);
                        }
                    });
                }
                else
                {
                    await Task.Run(() =>
                    {
                        Logger.LogEvent(Resources.Text.Nuget_UninstallingPackage, LogLevel.Status);

                        try
                        {
                            foreach (string packageId in packageIds)
                            {
                                IVsPackageUninstaller uninstaller = _componentModel.GetService <IVsPackageUninstaller>();
                                uninstaller.UninstallPackage(project, packageId, false);
                            }

                            Telemetry.TrackUserTask("Uninstall-NugetPackage");
                            Logger.LogEvent(Resources.Text.Nuget_PackageUninstalled, LogLevel.Status);
                        }
                        catch (Exception ex)
                        {
                            Telemetry.TrackException(nameof(RestoreOnBuildCommand), ex);
                            Logger.LogEvent(Resources.Text.Nuget_PackageFailedToUninstall, LogLevel.Status);
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                Telemetry.TrackException(nameof(RestoreOnBuildCommand), ex);
                Logger.LogEvent(Resources.Text.Nuget_PackageFailedToInstall, LogLevel.Status);
            }
        }
Esempio n. 14
0
 static void Realize(IVsPackageUninstaller uninstaller)
 {
     uninstaller.UninstallPackage(default(Project), default(string), default(bool));
 }
Esempio n. 15
0
        /// <summary>
        /// Removes packages. Will do a couple of passes in case packages rely on each other
        /// </summary>
        /// <param name="project"></param>
        /// <param name="ids"></param>
        /// <param name="token"></param>
        /// <param name="model"></param>
        private bool RemovePackages(Project project, IEnumerable <string> ids, CancellationToken token,
                                    ConverterUpdateViewModel model)
        {
            var retryCount  = new ConcurrentDictionary <string, int>(StringComparer.OrdinalIgnoreCase);
            var packages    = new Queue <string>(ids);
            var maxRetry    = packages.Count + 1;
            int maxAttempts = maxRetry * packages.Count;
            int counter     = 0;

            _logger.WriteLine($"{project.Name}: Packages: {packages.Count}, maxattempts: {maxAttempts}");
            while (packages.Count > 0 && counter < maxAttempts)
            {
                counter++;
                token.ThrowIfCancellationRequested();

                var package = packages.Dequeue();

                try
                {
                    model.Log = $"Uninstalling {package}";
                    _logger.WriteLine(model.Log + $" (counter = {counter})");

                    _uninstaller.UninstallPackage(project, package, false);
                    model.Log = $"Uninstalled {package}";
                    _logger.WriteLine(model.Log);
                    counter = 0;
                }
                catch (Exception e)
                {
                    if (e is InvalidOperationException)
                    {
                        model.Log = $"Invalid operation exception when uninstalling {package} ";
                        _logger.WriteLine(model.Log);
                        Debug.WriteLine(e.Message);
                    }
                    else
                    {
                        model.Log = $"Exception uninstalling {package} ";
                        _logger.WriteLine(model.Log);
                        Debug.WriteLine(e);
                    }

                    retryCount.AddOrUpdate(package, 1, (_, count) => count + 1);

                    if (retryCount[package] < maxRetry)
                    {
                        model.Log = $"{package} added back to queue";
                        _logger.WriteLine(model.Log);
                        packages.Enqueue(package);
                    }
                }
            }

            if (counter == maxAttempts)
            {
                model.Log = $"Could not uninstall all packages in {project.Name}";
                _logger.WriteLine(model.Log);
                System.Threading.Thread.Sleep(2000);
            }

            return(!retryCount.Values.Any(v => v >= maxRetry));
        }
 public void UninstallPackage(Project project, PackageModel Pkg, bool includeDependencies)
 {
     _PkgUninstaller.UninstallPackage(project, Pkg.Id, !includeDependencies);
 }