mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Refactor dotnet restore command invocation
This commit is contained in:
@@ -1,17 +1,51 @@
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Semmle.BuildAnalyser
|
||||
{
|
||||
/// <summary>
|
||||
/// Utilities to run the "dotnet" command.
|
||||
/// </summary>
|
||||
internal static class DotNet
|
||||
internal class DotNet
|
||||
{
|
||||
public static int RestoreToDirectory(string projectOrSolutionFile, string packageDirectory)
|
||||
private readonly ProgressMonitor progressMonitor;
|
||||
|
||||
public DotNet(ProgressMonitor progressMonitor)
|
||||
{
|
||||
using var proc = Process.Start("dotnet", $"restore --no-dependencies \"{projectOrSolutionFile}\" --packages \"{packageDirectory}\" /p:DisableImplicitNuGetFallbackFolder=true");
|
||||
this.progressMonitor = progressMonitor;
|
||||
Info();
|
||||
}
|
||||
|
||||
private void Info()
|
||||
{
|
||||
try
|
||||
{
|
||||
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}.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("dotnet --info failed.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void RestoreToDirectory(string projectOrSolutionFile, string packageDirectory)
|
||||
{
|
||||
var args = $"restore --no-dependencies \"{projectOrSolutionFile}\" --packages \"{packageDirectory}\" /p:DisableImplicitNuGetFallbackFolder=true";
|
||||
progressMonitor.RunningProcess($"dotnet {args}");
|
||||
using var proc = Process.Start("dotnet", args);
|
||||
proc.WaitForExit();
|
||||
return proc.ExitCode;
|
||||
if (proc.ExitCode != 0)
|
||||
{
|
||||
progressMonitor.CommandFailed("dotnet", args, proc.ExitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user