dotnet-installer/build_projects/Microsoft.DotNet.Cli.Build.Framework/BuildHelpers.cs

47 lines
2.3 KiB
C#
Raw Normal View History

2016-02-02 18:04:50 +00:00
using System.Collections.Generic;
namespace Microsoft.DotNet.Cli.Build.Framework
{
public static class BuildHelpers
{
public static int ExecInSilent(string workingDirectory, string command, params string[] args) => ExecInSilent(workingDirectory, command, (IEnumerable<string>)args);
public static int ExecInSilent(string workingDirectory, string command, IEnumerable<string> args) => ExecCore(command, args, workingDirectory, silent: true, env: null);
2016-02-02 18:04:50 +00:00
public static int ExecIn(string workingDirectory, string command, params string[] args) => ExecIn(workingDirectory, command, (IEnumerable<string>)args);
public static int ExecIn(string workingDirectory, string command, IEnumerable<string> args) => ExecCore(command, args, workingDirectory, silent: false, env: null);
2016-02-02 18:04:50 +00:00
public static int ExecSilent(string command, params string[] args) => ExecSilent(command, (IEnumerable<string>)args);
public static int ExecSilent(string command, IEnumerable<string> args) => ExecSilent(command, args, env: null);
2016-06-06 15:31:44 +00:00
public static int ExecSilent(string command, IEnumerable<string> args, IDictionary<string, string> env) => ExecCore(command, args, workingDirectory: null, silent: true, env: env);
2016-02-02 18:04:50 +00:00
public static int Exec(string command, params string[] args) => Exec(command, (IEnumerable<string>)args);
public static int Exec(string command, IEnumerable<string> args) => ExecCore(command, args, workingDirectory: null, silent: false, env: null);
2016-02-02 18:04:50 +00:00
public static Command Cmd(string command, params string[] args) => Cmd(command, (IEnumerable<string>)args);
public static Command Cmd(string command, IEnumerable<string> args)
{
return Command.Create(command, args);
}
internal static int ExecCore(string command, IEnumerable<string> args, string workingDirectory, bool silent, IDictionary<string, string> env)
2016-02-02 18:04:50 +00:00
{
var cmd = Cmd(command, args);
if (!string.IsNullOrEmpty(workingDirectory))
2016-02-02 18:04:50 +00:00
{
cmd.WorkingDirectory(workingDirectory);
}
if (silent)
2016-02-02 18:04:50 +00:00
{
cmd.CaptureStdErr().CaptureStdOut();
}
var result = cmd.Environment(env).Execute();
2016-02-02 18:04:50 +00:00
result.EnsureSuccessful();
return result.ExitCode;
}
2016-02-02 18:04:50 +00:00
}
}