Exemple #1
0
        public async Task Invoke(PackageInProject currentPackage,
                                 NuGetVersion newVersion, PackageSource packageSource, NuGetSources allSources)
        {
            var projectPath = currentPackage.Path.Info.DirectoryName;

            var nuget = _nuGetPath.Executable;

            if (string.IsNullOrWhiteSpace(nuget))
            {
                _logger.Normal("Cannot find NuGet.exe for package update");
                return;
            }

            var sources       = allSources.CommandLine("-Source");
            var updateCommand = $"update packages.config -Id {currentPackage.Id} -Version {newVersion} {sources} -NonInteractive";

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                if (await _monoExecutor.CanRun())
                {
                    await _monoExecutor.Run(projectPath, nuget, updateCommand, true);
                }
                else
                {
                    _logger.Error("Cannot run NuGet.exe. It requires either Windows OS Platform or Mono installation");
                }
            }
            else
            {
                await _externalProcess.Run(projectPath, nuget, updateCommand, true);
            }
        }
Exemple #2
0
        public async Task Invoke(FileInfo file, NuGetSources sources)
        {
            _logger.Normal($"Nuget restore on {file.DirectoryName} {file.Name}");

            var nuget = _nuGetPath.Executable;

            if (string.IsNullOrWhiteSpace(nuget))
            {
                _logger.Normal("Cannot find NuGet.exe for solution restore");
                return;
            }

            var sourcesCommandLine = sources.CommandLine("-Source");

            var restoreCommand = $"restore {file.Name} {sourcesCommandLine}  -NonInteractive";

            ProcessOutput processOutput;

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                if (await _monoExecutor.CanRun())
                {
                    processOutput = await _monoExecutor.Run(file.DirectoryName,
                                                            nuget,
                                                            restoreCommand,
                                                            ensureSuccess : false);
                }
                else
                {
                    _logger.Error("Cannot run NuGet.exe. It requires either Windows OS Platform or Mono installation");
                    return;
                }
            }
            else
            {
                processOutput = await _externalProcess.Run(file.DirectoryName,
                                                           nuget,
                                                           restoreCommand,
                                                           ensureSuccess : false);
            }

            if (processOutput.Success)
            {
                _logger.Detailed($"Nuget restore on {file.Name} complete");
            }
            else
            {
                _logger.Detailed(
                    $"Nuget restore failed on {file.DirectoryName} {file.Name}:\n{processOutput.Output}\n{processOutput.ErrorOutput}");
            }
        }
        public async Task Invoke(FileInfo file, NuGetSources sources)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            if (sources == null)
            {
                throw new ArgumentNullException(nameof(sources));
            }

            _logger.Normal($"Nuget restore on {file.DirectoryName} {file.Name}");

            var nuget = _nuGetPath.Executable;

            if (string.IsNullOrWhiteSpace(nuget))
            {
                _logger.Normal("Cannot find NuGet.exe for solution restore");
                return;
            }

            var    fileNameCommandLine = ArgumentEscaper.EscapeAndConcatenate(new[] { file.Name });
            var    sourcesCommandLine  = sources.CommandLine("-Source");
            string restoreCommand      = $"restore {fileNameCommandLine} {sourcesCommandLine} -NonInteractive";

            // see: https://docs.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-restore
            if (string.Equals(file.Name, "packages.config", StringComparison.OrdinalIgnoreCase))
            {
                restoreCommand = $"{restoreCommand} -PackagesDirectory ..\\packages";
            }

            ProcessOutput processOutput;

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                if (await _monoExecutor.CanRun())
                {
                    processOutput = await _monoExecutor.Run(file.DirectoryName,
                                                            nuget,
                                                            restoreCommand,
                                                            ensureSuccess : false);
                }
                else
                {
                    _logger.Error("Cannot run NuGet.exe. It requires either Windows OS Platform or Mono installation");
                    return;
                }
            }
            else
            {
                processOutput = await _externalProcess.Run(file.DirectoryName,
                                                           nuget,
                                                           restoreCommand,
                                                           ensureSuccess : false);
            }

            if (processOutput.Success)
            {
                _logger.Detailed($"Nuget restore on {file.Name} complete");
            }
            else
            {
                _logger.Detailed(
                    $"Nuget restore failed on {file.DirectoryName} {file.Name}:\n{processOutput.Output}\n{processOutput.ErrorOutput}");
            }
        }