Skip to content

Game.Modding.Toolchain.Dependencies.VisualStudioDependency

Assembly:
Game (toolchain/modding system)

Namespace:
Game.Modding.Toolchain.Dependencies

Type:
class

Base:
BaseIDEDependency

Summary:
Implements a dependency checker for Microsoft Visual Studio. This class does not provide installation or uninstallation logic; instead it detects installed Visual Studio instances by invoking vswhere.exe (expected to live under ToolchainDependencyManager.kGameToolingPath) and parsing its JSON output. It exposes metadata (name, icon, minimum required version) and uses CliWrap to execute the external vswhere tool. The class logs warnings/errors via the toolchain logging helpers when vswhere reports error output or when version detection fails.


Fields

  • public static string vsWhere
    Path to the vswhere.exe used to query installed Visual Studio instances. Built from ToolchainDependencyManager.kGameToolingPath + "/vswhere.exe". The tool must exist at this location for detection to work.

Properties

  • public override string name { get; }
    Returns "Visual Studio". Used as the human-readable name of this dependency.

  • public override string icon { get; }
    Returns "Media/Toolchain/VisualStudio.svg". Path to an icon used in the UI.

  • public override bool canBeInstalled { get; }
    Returns false. Visual Studio cannot be installed by the toolchain; it must be provided by the user / system.

  • public override bool canBeUninstalled { get; }
    Returns false. Visual Studio is not uninstalled by the toolchain.

  • public override string minVersion { get; }
    Returns "17.8". The minimum required Visual Studio build version for this toolchain.

Constructors

  • public VisualStudioDependency()
    Default constructor (inherited from class instantiation). No custom construction logic is defined in the source.

Methods

  • protected override Task<string> GetIDEVersion(CancellationToken token)
    Attempts to get the installed Visual Studio version. It calls an internal GetIDEVersion overload with "-prerelease -format json" and wraps the call in try/catch. If the first attempt throws, it retries once; if the second attempt fails it logs an error via ToolchainDependencyManager.log and returns an empty string. This method returns the buildVersion (string) or an empty string on failure.

  • private static async Task<string> GetIDEVersion(CancellationToken token, string arguments)
    Queries vswhere (via QueryVsWhere) and returns the buildVersion of the first entry in the returned JSON entries array. If there are no entries it returns an empty string.

  • private static async Task<VsWhereResult> QueryVsWhere(CancellationToken token, string arguments)
    Executes vswhere.exe using CliWrap to capture stdout and stderr. It:

  • Builds a JSON wrapper string with "{ \"entries\": " + + "}" so the output can be deserialized into a VsWhereResult object.
  • Collects stderr lines into a list and logs them as a warning (IToolchainDependency.log.Warn) if any are present.
  • Note: In the current implementation the method ignores the passed-in arguments parameter and uses hard-coded arguments "-prerelease -latest -format json" when invoking vswhere.exe.
  • Returns VsWhereResult.FromJson(...) parsed from the assembled JSON string.

Important behavior and notes: - The class depends on the VsWhereResult type to parse vswhere output. That type and its FromJson method must exist and match the JSON shape expected. - The code uses CliWrap to run external processes asynchronously and collects output via PipeTarget.ToDelegate. - Errors encountered while attempting detection are caught and logged; the system will fall back to reporting an empty version string when detection fails.

Usage Example

// Minimal usage showing the exposed metadata and the vswhere path.
// The actual version detection is implemented as a protected override and is
// invoked by the toolchain manager, so you typically don't call it directly.

var dep = new VisualStudioDependency();
Console.WriteLine(dep.name);          // "Visual Studio"
Console.WriteLine(dep.icon);          // "Media/Toolchain/VisualStudio.svg"
Console.WriteLine(dep.minVersion);    // "17.8"

// Path to the vswhere executable used by this dependency:
Console.WriteLine(VisualStudioDependency.vsWhere);

Additional notes: - Ensure vswhere.exe is present at ToolchainDependencyManager.kGameToolingPath; otherwise detection will fail. - The QueryVsWhere method currently uses a hard-coded argument set ("-prerelease -latest -format json") which differs from some callsites that pass other argument strings — this may be intentional or could be a point to review for correctness.