-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathIntegratedSetup.cs
More file actions
60 lines (48 loc) · 1.77 KB
/
IntegratedSetup.cs
File metadata and controls
60 lines (48 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
namespace ServiceControl.Infrastructure
{
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
public static class IntegratedSetup
{
const string SetupAndRunCmd = "--setup-and-run";
const string SetupCmd = "--setup";
public static async Task<int> Run()
{
// Using GetCommandLineArgs instead of the args passed into Main because GetCommandLineArgs provides the entry assembly path
var args = Environment.GetCommandLineArgs().ToList();
if (!args.Contains(SetupAndRunCmd))
{
return 0;
}
for (var i = 0; i < args.Count; i++)
{
if (args[i] == SetupAndRunCmd)
{
args[i] = SetupCmd;
}
}
var processPath = Environment.ProcessPath;
if (!Path.GetFileNameWithoutExtension(processPath).Equals("dotnet", StringComparison.OrdinalIgnoreCase))
{
args.RemoveAt(0);
}
var startInfo = new ProcessStartInfo(processPath, args)
{
UseShellExecute = false,
WorkingDirectory = Environment.CurrentDirectory,
RedirectStandardOutput = true,
RedirectStandardError = true
};
var process = Process.Start(startInfo);
process.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
process.ErrorDataReceived += (s, e) => Console.Error.WriteLine(e.Data);
process.BeginOutputReadLine();
process.BeginErrorReadLine();
await process.WaitForExitAsync();
return process.ExitCode;
}
}
}