From 291f7daeeccc16f5e89b3f671cddecdc0c277ad0 Mon Sep 17 00:00:00 2001 From: Tristan Moreaux Date: Fri, 15 Mar 2024 13:56:41 +0000 Subject: [PATCH] Add a function to retrieve the compiler version of the buildtools (version of cl.exe which is exposed as _MSC_FULL_VER preprocessor flag) Note : This is different from the product version. For example with Visual Studio 17.6.0, _MSC_FULL_VER is 193632532. The product version is 14.36.32532 (returned by GetVisualStudioVCToolsVersion) while CL.exe version is 19.36.32532 (returned by the new function). --- Sharpmake/ExtensionMethods.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sharpmake/ExtensionMethods.cs b/Sharpmake/ExtensionMethods.cs index fb8dda232..a4263c196 100644 --- a/Sharpmake/ExtensionMethods.cs +++ b/Sharpmake/ExtensionMethods.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; @@ -392,6 +393,13 @@ public static Version GetVisualStudioVCToolsVersion(this DevEnv visualVersion) return version; } + public static Version GetVisualStudioVCToolsCompilerVersion(this DevEnv visualVersion, Platform platform) + { + string clExeFile = Path.Combine(visualVersion.GetVisualStudioBinPath(platform), "cl.exe"); + FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(clExeFile); + return new Version(fileVersionInfo.FileMajorPart, fileVersionInfo.FileMinorPart, fileVersionInfo.FileBuildPart, fileVersionInfo.FilePrivatePart); + } + /// /// Will return the name of the root directory in MSBuild under Microsoft/VC for a particular devenv, /// since it uses yet another versioning pattern than the toolchain @@ -485,7 +493,7 @@ public static string GetVisualStudioBinPath(this DevEnv visualVersion, Platform case DevEnv.vs2019: case DevEnv.vs2022: { - string targetPlatform = (platform == Platform.win64) ? "x64" : "x86"; + string targetPlatform = (platform == Platform.win32) ? "x86" : "x64"; string compilerHost = Environment.Is64BitOperatingSystem ? "HostX64" : "HostX86"; return Path.Combine(visualVersion.GetVisualStudioVCRootPath(), "bin", compilerHost, targetPlatform); }