Skip to content

Commit

Permalink
Merge branch 'add-method-retrieve-cl-version' into 'main'
Browse files Browse the repository at this point in the history
Add a function to retrieve the compiler version of the buildtools (version of...

See merge request Sharpmake/sharpmake!499
  • Loading branch information
jspelletier committed Mar 15, 2024
2 parents b890493 + 291f7da commit 2ac5cb0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Sharpmake/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -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);
}

/// <summary>
/// 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
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 2ac5cb0

Please sign in to comment.