Esempio n. 1
0
        public void Add(FilePath projectPath, string packageId)
        {
            if (packageId == null)
            {
                throw new ArgumentNullException(nameof(packageId));
            }

            var argsToPassToRestore = new List <string>
            {
                projectPath.Value,
                "package",
                packageId,
                "--no-restore"
            };

            var command = new DotNetCommandFactory(alwaysRunOutOfProc: true)
                          .Create(
                "add",
                argsToPassToRestore)
                          .CaptureStdOut()
                          .CaptureStdErr();

            var result = command.Execute();

            if (result.ExitCode != 0)
            {
                throw new PackageObtainException("Failed to add package. " +
                                                 $"{Environment.NewLine}WorkingDirectory: " +
                                                 result.StartInfo.WorkingDirectory +
                                                 $"{Environment.NewLine}Arguments: " +
                                                 result.StartInfo.Arguments +
                                                 $"{Environment.NewLine}Output: " +
                                                 result.StdErr + result.StdOut);
            }
        }
        public void Add(FilePath projectPath, string packageId)
        {
            if (packageId == null)
            {
                throw new ArgumentNullException(nameof(packageId));
            }

            var argsToPassToRestore = new List <string>
            {
                projectPath.Value,
                "package",
                packageId,
                "--no-restore"
            };

            var command = new DotNetCommandFactory(alwaysRunOutOfProc: true)
                          .Create(
                "add",
                argsToPassToRestore)
                          .CaptureStdOut()
                          .CaptureStdErr();

            var result = command.Execute();

            if (result.ExitCode != 0)
            {
                throw new PackageObtainException(
                          string.Format(
                              LocalizableStrings.FailedToAddPackage,
                              result.StartInfo.WorkingDirectory, result.StartInfo.Arguments, result.StdErr, result.StdOut));
            }
        }
Esempio n. 3
0
        public void Restore(
            FilePath project,
            DirectoryPath assetJsonOutput,
            FilePath?nugetConfig = null,
            string source        = null,
            string verbosity     = null)
        {
            var argsToPassToRestore = new List <string>();

            argsToPassToRestore.Add(project.Value);
            if (nugetConfig != null)
            {
                argsToPassToRestore.Add("--configfile");
                argsToPassToRestore.Add(nugetConfig.Value.Value);
            }

            if (source != null)
            {
                argsToPassToRestore.Add("--source");
                argsToPassToRestore.Add(source);
            }

            argsToPassToRestore.AddRange(new List <string>
            {
                "--runtime",
                AnyRid,
                $"/p:BaseIntermediateOutputPath={assetJsonOutput.ToQuotedString()}"
            });

            argsToPassToRestore.Add($"/verbosity:{verbosity ?? "quiet"}");

            var command = new DotNetCommandFactory(alwaysRunOutOfProc: true)
                          .Create("restore", argsToPassToRestore);

            if (_reporter != null)
            {
                command = command
                          .OnOutputLine((line) => _reporter.WriteLine(line))
                          .OnErrorLine((line) => _reporter.WriteLine(line));
            }

            var result = command.Execute();

            if (result.ExitCode != 0)
            {
                throw new ToolPackageException(LocalizableStrings.ToolInstallationRestoreFailed);
            }
        }
        private void RunCommand(string commandToExecute, IEnumerable <string> args, string workingDirectory)
        {
            var command = new DotNetCommandFactory()
                          .Create(commandToExecute, args)
                          .WorkingDirectory(workingDirectory)
                          .CaptureStdOut()
                          .CaptureStdErr();

            var commandResult = command.Execute();

            if (commandResult.ExitCode != 0)
            {
                MigrationTrace.Instance.WriteLine(commandResult.StdOut);
                MigrationTrace.Instance.WriteLine(commandResult.StdErr);

                throw new Exception($"Failed to run {commandToExecute} in directory: {workingDirectory}");
            }
        }
Esempio n. 5
0
        public void Restore(FilePath project,
                            PackageLocation packageLocation,
                            string verbosity = null)
        {
            var argsToPassToRestore = new List <string>();

            argsToPassToRestore.Add(project.Value);
            if (packageLocation.NugetConfig != null)
            {
                argsToPassToRestore.Add("--configfile");
                argsToPassToRestore.Add(packageLocation.NugetConfig.Value.Value);
            }

            argsToPassToRestore.AddRange(new List <string>
            {
                "--runtime",
                Constants.AnyRid
            });

            argsToPassToRestore.Add($"--verbosity:{verbosity ?? GetDefaultVerbosity()}");

            if (_additionalRestoreArguments != null)
            {
                argsToPassToRestore.AddRange(_additionalRestoreArguments.Where(arg => !arg.StartsWith("-verbosity")));
            }

            var command = new DotNetCommandFactory(alwaysRunOutOfProc: true)
                          .Create("restore", argsToPassToRestore);

            if (verbosity == null || _forceOutputRedirection)
            {
                command = command
                          .OnOutputLine(line => WriteLine(_reporter, line, project))
                          .OnErrorLine(line => WriteLine(_errorReporter, line, project));
            }

            var result = command.Execute();

            if (result.ExitCode != 0)
            {
                throw new ToolPackageException(LocalizableStrings.ToolInstallationRestoreFailed);
            }
        }
Esempio n. 6
0
        public void Restore(
            FilePath projectPath,
            DirectoryPath assetJsonOutput,
            FilePath?nugetconfig,
            string source = null)
        {
            var argsToPassToRestore = new List <string>();

            argsToPassToRestore.Add(projectPath.Value);
            if (nugetconfig != null)
            {
                argsToPassToRestore.Add("--configfile");
                argsToPassToRestore.Add(nugetconfig.Value.Value);
            }

            if (source != null)
            {
                argsToPassToRestore.Add("--source");
                argsToPassToRestore.Add(source);
            }

            argsToPassToRestore.AddRange(new List <string>
            {
                "--runtime",
                RuntimeEnvironment.GetRuntimeIdentifier(),
                $"/p:BaseIntermediateOutputPath={assetJsonOutput.ToQuotedString()}"
            });

            var command = new DotNetCommandFactory(alwaysRunOutOfProc: true)
                          .Create("restore", argsToPassToRestore)
                          .CaptureStdOut()
                          .CaptureStdErr();

            var result = command.Execute();

            if (result.ExitCode != 0)
            {
                throw new PackageObtainException(
                          string.Format(
                              LocalizableStrings.FailedToRestorePackage,
                              result.StartInfo.WorkingDirectory, result.StartInfo.Arguments, result.StdErr, result.StdOut));
            }
        }
Esempio n. 7
0
        private void RunCommand(string commandToExecute, IEnumerable <string> args, string workingDirectory)
        {
            var command = new DotNetCommandFactory()
                          .Create(commandToExecute, args)
                          .WorkingDirectory(workingDirectory)
                          .CaptureStdOut()
                          .CaptureStdErr();

            var commandResult = command.Execute();

            if (commandResult.ExitCode != 0)
            {
                string argList = string.Join(", ", args);
                throw new GracefulException($"Failed to run {commandToExecute} with " +
                                            $"args: {argList} ... " +
                                            $"workingDirectory = {workingDirectory}, " +
                                            $"StdOut = {commandResult.StdOut}, " +
                                            $"StdErr = {commandResult.StdErr}");
            }
        }
Esempio n. 8
0
        public void Restore(FilePath project,
                            FilePath?nugetConfig = null,
                            string verbosity     = null)
        {
            var argsToPassToRestore = new List <string>();

            argsToPassToRestore.Add(project.Value);
            if (nugetConfig != null)
            {
                argsToPassToRestore.Add("--configfile");
                argsToPassToRestore.Add(nugetConfig.Value.Value);
            }

            argsToPassToRestore.AddRange(new List <string>
            {
                "--runtime",
                AnyRid
            });

            argsToPassToRestore.Add($"-verbosity:{verbosity ?? "quiet"}");

            var command = new DotNetCommandFactory(alwaysRunOutOfProc: true)
                          .Create("restore", argsToPassToRestore);

            if (verbosity == null || _forceOutputRedirection)
            {
                command = command
                          .OnOutputLine(line => WriteLine(_reporter, line, project))
                          .OnErrorLine(line => WriteLine(_errorReporter, line, project));
            }

            var result = command.Execute();

            if (result.ExitCode != 0)
            {
                throw new ToolPackageException(LocalizableStrings.ToolInstallationRestoreFailed);
            }
        }