mirror of
https://github.com/github/codeql.git
synced 2025-12-23 20:26:32 +01:00
C#: Use dotnet --list-runtimes to find runtime locations.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Semmle.Util;
|
||||
|
||||
namespace Semmle.BuildAnalyser
|
||||
{
|
||||
@@ -8,6 +10,7 @@ namespace Semmle.BuildAnalyser
|
||||
/// </summary>
|
||||
internal class DotNet
|
||||
{
|
||||
private const string dotnet = "dotnet";
|
||||
private readonly ProgressMonitor progressMonitor;
|
||||
|
||||
public DotNet(ProgressMonitor progressMonitor)
|
||||
@@ -19,26 +22,26 @@ namespace Semmle.BuildAnalyser
|
||||
private void Info()
|
||||
{
|
||||
// TODO: make sure the below `dotnet` version is matching the one specified in global.json
|
||||
progressMonitor.RunningProcess("dotnet --info");
|
||||
using var proc = Process.Start("dotnet", "--info");
|
||||
progressMonitor.RunningProcess($"{dotnet} --info");
|
||||
using var proc = Process.Start(dotnet, "--info");
|
||||
proc.WaitForExit();
|
||||
var ret = proc.ExitCode;
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
progressMonitor.CommandFailed("dotnet", "--info", ret);
|
||||
throw new Exception($"dotnet --info failed with exit code {ret}.");
|
||||
progressMonitor.CommandFailed(dotnet, "--info", ret);
|
||||
throw new Exception($"{dotnet} --info failed with exit code {ret}.");
|
||||
}
|
||||
}
|
||||
|
||||
private bool RunCommand(string args)
|
||||
{
|
||||
progressMonitor.RunningProcess($"dotnet {args}");
|
||||
using var proc = Process.Start("dotnet", args);
|
||||
progressMonitor.RunningProcess($"{dotnet} {args}");
|
||||
using var proc = Process.Start(dotnet, args);
|
||||
proc.WaitForExit();
|
||||
if (proc.ExitCode != 0)
|
||||
{
|
||||
progressMonitor.CommandFailed("dotnet", args, proc.ExitCode);
|
||||
progressMonitor.CommandFailed(dotnet, args, proc.ExitCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -62,5 +65,22 @@ namespace Semmle.BuildAnalyser
|
||||
var args = $"add \"{folder}\" package \"{package}\" --no-restore";
|
||||
return RunCommand(args);
|
||||
}
|
||||
|
||||
public IList<string> GetListedRuntimes()
|
||||
{
|
||||
var args = "--list-runtimes";
|
||||
var pi = new ProcessStartInfo(dotnet, args)
|
||||
{
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false
|
||||
};
|
||||
var exitCode = pi.ReadOutput(out var runtimes);
|
||||
if (exitCode != 0)
|
||||
{
|
||||
progressMonitor.CommandFailed(dotnet, args, exitCode);
|
||||
return new List<string>();
|
||||
}
|
||||
return runtimes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user