/// Returns the exit code. public static int ExecutePowershell(this SetupContext context, params string[] args) { Debug.Assert(args.Length > 0); List <string> allArgs = new List <string> { "-ExecutionPolicy", "Unrestricted", }; allArgs.AddRange(args); ProcessStartInfo processStartInfo = new ProcessStartInfo(DefaultPowershellExePath) { Arguments = ToProcessArgumentsString(allArgs), UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, }; int exitCode = 0; context.RunProcess(processStartInfo, (proc) => exitCode = proc.ExitCode); return(exitCode); }
public static int ExecuteChocolatey(this SetupContext context, params string[] args) { Debug.Assert(args.Length > 0); ProcessStartInfo startInfo = new ProcessStartInfo(DefaultChocoExePath) { Arguments = ToProcessArgumentsString(args), UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, }; int exitCode = 0; context.RunProcess(startInfo, (proc) => exitCode = proc.ExitCode); return(exitCode); }
public static void CloneGitRepository(SetupContext context, string gitExePath, string url, string destination, int depth = 0, bool recursive = false) { if (!Path.IsPathRooted(destination)) { throw new ArgumentException( "The given destination path must be an absolute path!", nameof(destination)); } Console.WriteLine($"Cloning git repository: \"{url}\""); Console.WriteLine($"Repository destination: \"{destination}\""); if (Directory.Exists(Path.Combine(destination, ".git"))) { Console.Error.WriteLine("Repo already exists. Not cloning it again."); } else { List <string> args = new List <string> { "clone", url, destination }; if (depth > 0) { args.Add($"--depth={depth}"); } if (recursive) { args.Add("--recursive"); } ProcessStartInfo processStartInfo = new ProcessStartInfo(gitExePath) { Arguments = ToProcessArgumentsString(args), CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, }; context.RunProcess(processStartInfo); } }