Exemplo n.º 1
0
        public override Task ExecuteCommandAsync()
        {
            if (DisableParallelProcessing)
            {
                HttpSourceResourceProvider.Throttle = SemaphoreSlimThrottle.CreateBinarySemaphore();
            }

            CalculateEffectivePackageSaveMode();
            CalculateEffectiveSettings();
            string installPath = ResolveInstallPath();

            string configFilePath = Path.GetFullPath(Arguments.Count == 0 ? Constants.PackageReferenceFile : Arguments[0]);
            string configFileName = Path.GetFileName(configFilePath);

            // If the first argument is a packages.xxx.config file, install everything it lists
            // Otherwise, treat the first argument as a package Id
            if (CommandLineUtility.IsValidConfigFileName(configFileName))
            {
                Prerelease = true;

                // display opt-out message if needed
                if (Console != null && RequireConsent &&
                    new PackageRestoreConsent(Settings).IsGranted)
                {
                    string message = String.Format(
                        CultureInfo.CurrentCulture,
                        LocalizedResourceManager.GetString("RestoreCommandPackageRestoreOptOutMessage"),
                        NuGetResources.PackageRestoreConsentCheckBoxText.Replace("&", ""));
                    Console.WriteLine(message);
                }

                return(PerformV2Restore(configFilePath, installPath));
            }
            else
            {
                var packageId = Arguments[0];
                var version   = Version != null ? new NuGetVersion(Version) : null;
                return(InstallPackage(packageId, version, installPath));
            }
        }
Exemplo n.º 2
0
        public override async Task ExecuteCommandAsync()
        {
            // update with self as parameter
            if (Self)
            {
                var selfUpdater = new SelfUpdater(repositoryFactory: RepositoryFactory)
                {
                    Console = Console
                };
                selfUpdater.UpdateSelf(Prerelease);
                return;
            }

            string inputFile = GetInputFile();

            if (string.IsNullOrEmpty(inputFile))
            {
                throw new CommandLineException(NuGetResources.InvalidFile);
            }

            _msbuildDirectory = MsBuildUtility.GetMsBuildDirectoryFromMsBuildPath(MSBuildPath, MSBuildVersion, Console).Value.Path;
            var context = new UpdateConsoleProjectContext(Console, FileConflictAction);

            var logger = new LoggerAdapter(context);
            var signedPackageVerifier         = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());
            var signedPackageVerifierSettings = SignedPackageVerifierSettings.GetClientPolicy(Settings, logger);

            context.PackageExtractionContext = new PackageExtractionContext(
                PackageSaveMode.Defaultv2,
                PackageExtractionBehavior.XmlDocFileSaveMode,
                logger,
                signedPackageVerifier,
                signedPackageVerifierSettings);

            string inputFileName = Path.GetFileName(inputFile);

            // update with packages.config as parameter
            if (CommandLineUtility.IsValidConfigFileName(inputFileName))
            {
                await UpdatePackagesAsync(inputFile, context);

                return;
            }

            // update with project file as parameter
            if (ProjectHelper.SupportedProjectExtensions.Contains(Path.GetExtension(inputFile) ?? string.Empty))
            {
                if (!File.Exists(inputFile))
                {
                    throw new CommandLineException(NuGetResources.UnableToFindProject, inputFile);
                }

                var projectSystem = new MSBuildProjectSystem(
                    _msbuildDirectory,
                    inputFile,
                    context);
                await UpdatePackagesAsync(projectSystem, GetRepositoryPath(projectSystem.ProjectFullPath));

                return;
            }

            if (!File.Exists(inputFile))
            {
                throw new CommandLineException(NuGetResources.UnableToFindSolution, inputFile);
            }

            // update with solution as parameter
            string solutionDir = Path.GetDirectoryName(inputFile);

            await UpdateAllPackages(solutionDir, context);
        }