mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
C#: Add proper .NET environment for dotnet info and list-sdks and streamline the minimal dotnet environment.
This commit is contained in:
@@ -84,11 +84,7 @@ namespace Semmle.Autobuild.CSharp
|
|||||||
var temp = FileUtils.GetTemporaryWorkingDirectory(builder.Actions.GetEnvironmentVariable, builder.Options.Language.UpperCaseName, out var shouldCleanUp);
|
var temp = FileUtils.GetTemporaryWorkingDirectory(builder.Actions.GetEnvironmentVariable, builder.Options.Language.UpperCaseName, out var shouldCleanUp);
|
||||||
return DotNet.WithDotNet(builder.Actions, builder.Logger, builder.Paths.Select(x => x.Item1), temp, shouldCleanUp, ensureDotNetAvailable, builder.Options.DotNetVersion, installDir =>
|
return DotNet.WithDotNet(builder.Actions, builder.Logger, builder.Paths.Select(x => x.Item1), temp, shouldCleanUp, ensureDotNetAvailable, builder.Options.DotNetVersion, installDir =>
|
||||||
{
|
{
|
||||||
var env = new Dictionary<string, string>
|
var env = DotNet.MinimalEnvironment.ToDictionary();
|
||||||
{
|
|
||||||
{ "DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "true" },
|
|
||||||
{ "MSBUILDDISABLENODEREUSE", "1" }
|
|
||||||
};
|
|
||||||
if (installDir is not null)
|
if (installDir is not null)
|
||||||
{
|
{
|
||||||
// The installation succeeded, so use the newly installed .NET
|
// The installation succeeded, so use the newly installed .NET
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
@@ -140,6 +141,8 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
// The version number should be kept in sync with the version .NET version used for building the application.
|
// The version number should be kept in sync with the version .NET version used for building the application.
|
||||||
public const string LatestDotNetSdkVersion = "9.0.300";
|
public const string LatestDotNetSdkVersion = "9.0.300";
|
||||||
|
|
||||||
|
public static ReadOnlyDictionary<string, string> MinimalEnvironment => IDotNetCliInvoker.MinimalEnvironment;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a script for downloading relevant versions of the
|
/// Returns a script for downloading relevant versions of the
|
||||||
/// .NET SDK. The SDK(s) will be installed at <code>installDir</code>
|
/// .NET SDK. The SDK(s) will be installed at <code>installDir</code>
|
||||||
@@ -289,7 +292,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var dotnetInfo = new CommandBuilder(actions).
|
var dotnetInfo = new CommandBuilder(actions, environment: MinimalEnvironment).
|
||||||
RunCommand(actions.PathCombine(path, "dotnet")).
|
RunCommand(actions.PathCombine(path, "dotnet")).
|
||||||
Argument("--info").Script;
|
Argument("--info").Script;
|
||||||
|
|
||||||
@@ -321,7 +324,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
|
|
||||||
private static BuildScript GetInstalledSdksScript(IBuildActions actions)
|
private static BuildScript GetInstalledSdksScript(IBuildActions actions)
|
||||||
{
|
{
|
||||||
var listSdks = new CommandBuilder(actions, silent: true).
|
var listSdks = new CommandBuilder(actions, silent: true, environment: MinimalEnvironment).
|
||||||
RunCommand("dotnet").
|
RunCommand("dotnet").
|
||||||
Argument("--list-sdks");
|
Argument("--list-sdks");
|
||||||
return listSdks.Script;
|
return listSdks.Script;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Semmle.Util;
|
using Semmle.Util;
|
||||||
using Semmle.Util.Logging;
|
using Semmle.Util.Logging;
|
||||||
@@ -36,10 +37,12 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
{
|
{
|
||||||
startInfo.WorkingDirectory = workingDirectory;
|
startInfo.WorkingDirectory = workingDirectory;
|
||||||
}
|
}
|
||||||
// Set the .NET CLI language to English to avoid localized output.
|
|
||||||
startInfo.EnvironmentVariables["DOTNET_CLI_UI_LANGUAGE"] = "en";
|
// Set minimal environment variables.
|
||||||
startInfo.EnvironmentVariables["MSBUILDDISABLENODEREUSE"] = "1";
|
foreach (var kvp in IDotNetCliInvoker.MinimalEnvironment)
|
||||||
startInfo.EnvironmentVariables["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "true";
|
{
|
||||||
|
startInfo.EnvironmentVariables[kvp.Key] = kvp.Value;
|
||||||
|
}
|
||||||
|
|
||||||
// Configure the proxy settings, if applicable.
|
// Configure the proxy settings, if applicable.
|
||||||
if (this.proxy != null)
|
if (this.proxy != null)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
namespace Semmle.Extraction.CSharp.DependencyFetching
|
namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||||
{
|
{
|
||||||
@@ -9,6 +10,18 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
string Exec { get; }
|
string Exec { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A minimal environment for running the .NET CLI.
|
||||||
|
///
|
||||||
|
/// The .NET CLI language is set to English to avoid localized output.
|
||||||
|
/// </summary>
|
||||||
|
static ReadOnlyDictionary<string, string> MinimalEnvironment { get; } = new(new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{"DOTNET_CLI_UI_LANGUAGE", "en"},
|
||||||
|
{"MSBUILDDISABLENODEREUSE", "1"},
|
||||||
|
{"DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "true"}
|
||||||
|
});
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Execute `dotnet <paramref name="args"/>` and return true if the command succeeded, otherwise false.
|
/// Execute `dotnet <paramref name="args"/>` and return true if the command succeeded, otherwise false.
|
||||||
/// If `silent` is true the output of the command is logged as `debug` otherwise as `info`.
|
/// If `silent` is true the output of the command is logged as `debug` otherwise as `info`.
|
||||||
|
|||||||
Reference in New Issue
Block a user