C#: Add proper .NET environment for dotnet info and list-sdks and streamline the minimal dotnet environment.

This commit is contained in:
Michael Nebel
2025-11-18 16:31:09 +01:00
parent 0daee6fbf2
commit fba496f911
4 changed files with 26 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.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.
public const string LatestDotNetSdkVersion = "9.0.300";
public static ReadOnlyDictionary<string, string> MinimalEnvironment => IDotNetCliInvoker.MinimalEnvironment;
/// <summary>
/// Returns a script for downloading relevant versions of the
/// .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")).
Argument("--info").Script;
@@ -321,7 +324,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
private static BuildScript GetInstalledSdksScript(IBuildActions actions)
{
var listSdks = new CommandBuilder(actions, silent: true).
var listSdks = new CommandBuilder(actions, silent: true, environment: MinimalEnvironment).
RunCommand("dotnet").
Argument("--list-sdks");
return listSdks.Script;