Пример #1
0
        public async Task InstallPackageAsync(IPackageDetails package, bool allowedPrerelease = false, CancellationToken token = default)
        {
            Argument.IsNotNull(() => package);

            var installedIdentity = package.GetIdentity();
            var operationPath     = _defaultProject.GetInstallPath(installedIdentity);

            try
            {
                ValidatePackage(package);

                //repositories retrieved inside package manager now
                //todo use PackageOperationContextService instead on repositoryContextService

                //here was used a flag 'ignoreDependencies = false' and 'ignoreWalkInfo = false' in old code

                _packageOperationNotificationService.NotifyOperationStarting(operationPath, PackageOperationType.Install, package);
                await _nuGetPackageManager.InstallPackageForProjectAsync(_defaultProject, package.GetIdentity(), token);
            }
            catch (Exception ex)
            {
                await _logger.LogAsync(LogLevel.Error, ex.Message);

                _packageOperationContextService.CurrentContext.Exceptions.Add(ex);
            }
            finally
            {
                FinishOperation(PackageOperationType.Install, operationPath, package);
            }
        }
Пример #2
0
        public async Task UpdatePackagesAsync(IPackageDetails package, bool allowedPrerelease = false, CancellationToken token = default)
        {
            Argument.IsNotNull(() => package);

            var updateIdentity = package.GetIdentity();
            var installPath    = _defaultProject.GetInstallPath(updateIdentity);

            // create current version identity
            var currentVersion = await _nuGetPackageManager.GetVersionInstalledAsync(_defaultProject, updateIdentity.Id, token);

            var currentIdentity = new PackageIdentity(updateIdentity.Id, currentVersion);

            if (currentIdentity.Version is null)
            {
                // Can be because of mismatch between packages.config and package files

                _logger.LogWarning($"Could not find existing local files for installed '{package.Id}'. Continue update to version '{updateIdentity.Version}'");

                ValidatePackage(package);
                _packageOperationNotificationService.NotifyOperationStarting(installPath, PackageOperationType.Install, package);

                await _nuGetPackageManager.UpdatePackageForProjectAsync(_defaultProject, updateIdentity.Id, updateIdentity.Version, token);

                return;
            }
            var uninstallPath = _defaultProject.GetInstallPath(currentIdentity);

            try
            {
                ValidatePackage(package);

                _packageOperationNotificationService.NotifyOperationStarting(installPath, PackageOperationType.Update, package); // install path is same as update

                // notify about uninstall and install because update in fact is combination of these actions
                // this also allow us provide different InstallPaths on notifications

                _packageOperationNotificationService.NotifyOperationStarting(uninstallPath, PackageOperationType.Uninstall, package);

                _packageOperationNotificationService.NotifyOperationStarting(installPath, PackageOperationType.Install, package);

                await _nuGetPackageManager.UpdatePackageForProjectAsync(_defaultProject, updateIdentity.Id, updateIdentity.Version, token);
            }
            catch (Exception ex)
            {
                await _logger.LogAsync(LogLevel.Error, ex.Message);

                _packageOperationContextService.CurrentContext.Exceptions.Add(ex);
            }
            finally
            {
                FinishOperation(PackageOperationType.Uninstall, uninstallPath, package);
                FinishOperation(PackageOperationType.Install, installPath, package);
                FinishOperation(PackageOperationType.Update, installPath, package); // The install path the same for update;
            }
        }
Пример #3
0
        public async Task UninstallPackageAsync(IPackageDetails package, CancellationToken token = default)
        {
            Argument.IsNotNull(() => package);

            var uninstalledIdentity = package.GetIdentity();
            var uninstallPath       = _defaultProject.GetInstallPath(uninstalledIdentity);

            try
            {
                //nuPackage should provide identity of installed package, which targeted for uninstall action
                _packageOperationNotificationService.NotifyOperationStarting(uninstallPath, PackageOperationType.Uninstall, package);
                await _nuGetPackageManager.UninstallPackageForProjectAsync(_defaultProject, package.GetIdentity(), token);
            }
            catch (Exception ex)
            {
                await _logger.LogAsync(LogLevel.Error, ex.Message);

                _packageOperationContextService.CurrentContext.Exceptions.Add(ex);
            }
            finally
            {
                FinishOperation(PackageOperationType.Uninstall, uninstallPath, package);
            }
        }