Skip to content

Commit ba0cc76

Browse files
committed
Minor cleanup of dotnet CLI invocations
1 parent ad3cc8e commit ba0cc76

File tree

1 file changed

+8
-22
lines changed
  • csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching

1 file changed

+8
-22
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DotNet.cs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,24 @@ public DotNet(ProgressMonitor progressMonitor)
2222
private void Info()
2323
{
2424
// TODO: make sure the below `dotnet` version is matching the one specified in global.json
25-
progressMonitor.RunningProcess($"{dotnet} --info");
26-
using var proc = Process.Start(dotnet, "--info");
27-
proc.WaitForExit();
28-
var ret = proc.ExitCode;
29-
30-
if (ret != 0)
25+
var res = RunCommand("--info");
26+
if (!res)
3127
{
32-
progressMonitor.CommandFailed(dotnet, "--info", ret);
33-
throw new Exception($"{dotnet} --info failed with exit code {ret}.");
28+
throw new Exception($"{dotnet} --info failed.");
3429
}
3530
}
3631

37-
private static ProcessStartInfo MakeDotnetStartInfo(string args) =>
32+
private static ProcessStartInfo MakeDotnetStartInfo(string args, bool redirectStandardOutput) =>
3833
new ProcessStartInfo(dotnet, args)
3934
{
4035
UseShellExecute = false,
41-
RedirectStandardOutput = true
36+
RedirectStandardOutput = redirectStandardOutput
4237
};
4338

44-
private bool RunCommandAux(string args, bool silent)
39+
private bool RunCommand(string args)
4540
{
4641
progressMonitor.RunningProcess($"{dotnet} {args}");
47-
using var proc = silent
48-
? Process.Start(MakeDotnetStartInfo(args))
49-
: Process.Start(dotnet, args);
42+
using var proc = Process.Start(MakeDotnetStartInfo(args, redirectStandardOutput: false));
5043
proc?.WaitForExit();
5144
var exitCode = proc?.ExitCode ?? -1;
5245
if (exitCode != 0)
@@ -57,12 +50,6 @@ private bool RunCommandAux(string args, bool silent)
5750
return true;
5851
}
5952

60-
private bool RunCommand(string args) =>
61-
RunCommandAux(args, false);
62-
63-
private bool RunCommandSilently(string args) =>
64-
RunCommandAux(args, true);
65-
6653
public bool RestoreToDirectory(string projectOrSolutionFile, string packageDirectory, string? pathToNugetConfig = null)
6754
{
6855
var args = $"restore --no-dependencies \"{projectOrSolutionFile}\" --packages \"{packageDirectory}\" /p:DisableImplicitNuGetFallbackFolder=true";
@@ -90,7 +77,7 @@ public bool AddPackage(string folder, string package)
9077
private IList<string> GetListed(string args, string artifact)
9178
{
9279
progressMonitor.RunningProcess($"{dotnet} {args}");
93-
var pi = MakeDotnetStartInfo(args);
80+
var pi = MakeDotnetStartInfo(args, redirectStandardOutput: true);
9481
var exitCode = pi.ReadOutput(out var artifacts);
9582
if (exitCode != 0)
9683
{
@@ -104,7 +91,6 @@ private IList<string> GetListed(string args, string artifact)
10491
public bool Exec(string execArgs)
10592
{
10693
var args = $"exec {execArgs}";
107-
//return RunCommandSilently(args);
10894
return RunCommand(args);
10995
}
11096
}

0 commit comments

Comments
 (0)