NuGetGallery.FunctionalTests.CommandlineHelper.InvokeNugetProcess C# (CSharp) Method

InvokeNugetProcess() public method

Invokes nuget.exe with the appropriate parameters.
public InvokeNugetProcess ( List arguments, string workingDir = null, int timeout = 360 ) : Task
arguments List cmd line args to NuGet.exe
workingDir string working dir if any to be used
timeout int Timeout in seconds (default = 6min).
return Task
        public async Task<ProcessResult> InvokeNugetProcess(List<string> arguments, string workingDir = null, int timeout = 360)
        {
            var nugetProcess = new Process();
            var pathToNugetExe = Path.Combine(Environment.CurrentDirectory, NugetExePath);

            arguments.Add(NonInteractiveSwitchString);
            var argumentsString = string.Join(" ", arguments);

            WriteLine("The NuGet.exe command to be executed is: " + pathToNugetExe + " " + argumentsString);

            // During the actual test run, a script will copy the latest NuGet.exe and overwrite the existing one
            ProcessStartInfo nugetProcessStartInfo = new ProcessStartInfo(pathToNugetExe);
            nugetProcessStartInfo.Arguments = argumentsString;
            nugetProcessStartInfo.RedirectStandardError = true;
            nugetProcessStartInfo.RedirectStandardOutput = true;
            nugetProcessStartInfo.RedirectStandardInput = true;
            nugetProcessStartInfo.UseShellExecute = false;
            nugetProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            nugetProcessStartInfo.CreateNoWindow = true;
            nugetProcess.StartInfo = nugetProcessStartInfo;

            if (workingDir != null)
            {
                nugetProcess.StartInfo.WorkingDirectory = workingDir;
            }

            nugetProcess.Start();

            var standardError = await nugetProcess.StandardError.ReadToEndAsync();
            var standardOutput = await nugetProcess.StandardOutput.ReadToEndAsync();


            WriteLine(standardOutput);

            if (!string.IsNullOrEmpty(standardError))
            {
                WriteLine(standardError);
            }

            nugetProcess.WaitForExit(timeout * 1000);

            var processResult = new ProcessResult(nugetProcess.ExitCode, standardError);
            return processResult;
        }

Usage Example

        private async Task <string> CreatePackageWithTargetFrameworkInternal(string nuspecFileFullPath, string frameworkVersion)
        {
            string nuspecDir = Path.GetDirectoryName(nuspecFileFullPath);

            AddContent(nuspecDir, frameworkVersion);
            AddLib(nuspecDir, frameworkVersion);
            var arguments = string.Join(string.Empty, CommandlineHelper.PackCommandString, @"""" + nuspecFileFullPath + @"""", CommandlineHelper.OutputDirectorySwitchString, @"""" + nuspecDir + @"""");

            var commandlineHelper = new CommandlineHelper(TestOutputHelper);
            await commandlineHelper.InvokeNugetProcess(arguments, Path.GetFullPath(Path.GetDirectoryName(nuspecFileFullPath)));

            string[] nupkgFiles = Directory.GetFiles(nuspecDir, "*.nupkg").ToArray();
            return(nupkgFiles.Length == 0 ? null : nupkgFiles[0]);
        }
All Usage Examples Of NuGetGallery.FunctionalTests.CommandlineHelper::InvokeNugetProcess