Пример #1
0
        /// <summary>
        ///     Uninstalls the specified <paramref name="package"/>.
        /// </summary>
        /// <param name="package">The <see cref="IPackage"/> to uninstall.</param>
        /// <returns>A Result containing the result of the operation.</returns>
        public IResult UninstallPackage(IPackage package)
        {
            Guid guid = logger.EnterMethod(xLogger.Params(package), true);

            logger.Info($"Uninstalling Package '{package?.FQN}' from '{package?.DirectoryName}'...");

            IResult retVal = new Result();

            if (package == default(IPackage))
            {
                retVal.AddError($"The specified Package is null.");
            }
            else if (string.IsNullOrEmpty(package.DirectoryName))
            {
                retVal.AddError($"The specified Package contains a null or empty DirectoryName.");
            }
            else if (!Platform.DirectoryExists(package.DirectoryName))
            {
                retVal.AddError($"The specified Package directory '{package.DirectoryName}' can not be found.");
            }
            else
            {
                retVal.Incorporate(Platform.DeleteDirectory(package.DirectoryName, true));
            }

            if (retVal.ResultCode != ResultCode.Failure)
            {
                logger.Debug($"Package {package.FQN} uninstalled successfully.  Sending PackageUninstalled Event...");
                Task.Run(() => PackageUninstalled?.Invoke(this, new PackageInstallEventArgs(package, package.DirectoryName)));
            }

            retVal.LogResult(logger);
            logger.ExitMethod(guid);
            return(retVal);
        }
Пример #2
0
        public async Task UninstallAsync(IEnumerable <NuGetProject> projects, IEnumerable <string> packages, bool removeDependencies, bool forceRemove, bool shouldThrow, CancellationToken token)
        {
            MyProjectContext projectContext = new MyProjectContext(FileConflictAction.OverwriteAll)
            {
                ActionType = NuGetActionType.Uninstall,
                PackageExtractionContext = _packageExtractionContext
            };

            // sort packages
            // packages = SortPackagesWhenUninstallAsync(projects, packages);

            foreach (string packageId in packages)
            {
                var uninstallationContext = new UninstallationContext(removeDependencies, forceRemove);
                IReadOnlyList <ResolvedAction> actions = await GetActionsForUninstallAsync(
                    uninstallationContext : uninstallationContext,
                    targets : projects,
                    packageId : packageId,
                    projectContext : projectContext,
                    token : token);

                if (actions.Count != 0)
                {
                    PackageUninstalling?.Invoke(packageId);

                    try
                    {
                        await ExecuteActionsAsync(actions, null, projectContext, NullSourceCacheContext.Instance, token);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                        if (shouldThrow)
                        {
                            throw;
                        }
                    }
                    finally
                    {
                        PackageUninstalled?.Invoke(packageId);
                    }
                }
            }
        }
Пример #3
0
 private void NuGetPackageUninstalled(string packageId)
 {
     PackageUninstalled?.Invoke(packageId);
 }
 public void OnPackageUninstalled(IDotNetProject project, NuGet.ProjectManagement.PackageEventArgs e)
 {
     PackageUninstalled?.Invoke(this, new PackageManagementEventArgs(project, e));
 }