private async Task UpdateSelfAsync()
        {
            PackageSource targetSource;

            switch (Source.Count)
            {
            case 0:
                targetSource = new PackageSource(NuGetConstants.V3FeedUrl);
                break;

            case 1:
                // Use the package source from the load config to preload any creds that might be needed for authentication.
                var availableSources = SourceProvider.LoadPackageSources().Where(source => source.IsEnabled);
                targetSource = Common.PackageSourceProviderExtensions.ResolveSource(availableSources, Source.Single());
                break;

            default:
                throw new CommandException(NuGetResources.Error_UpdateSelf_Source);
            }
            var selfUpdater = new SelfUpdater(Console);
            await selfUpdater.UpdateSelfAsync(Prerelease, targetSource);
        }
Esempio n. 2
0
        public override async Task ExecuteCommandAsync()
        {
            // update with self as parameter
            if (Self)
            {
                var selfUpdater = new SelfUpdater(Console);
                await selfUpdater.UpdateSelfAsync(Prerelease, NuGetConstants.V3FeedUrl);

                return;
            }

            string inputFile = GetInputFile();

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

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

            var logger = new LoggerAdapter(context);
            var clientPolicyContext = ClientPolicyContext.GetClientPolicy(Settings, logger);

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

            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 CommandException(NuGetResources.UnableToFindProject, inputFile);
                }

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

                return;
            }

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

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

            await UpdateAllPackages(solutionDir, context);
        }