diff --git a/Sharpmake/ExtensionMethods.cs b/Sharpmake/ExtensionMethods.cs index 675997327..d1de6f2eb 100644 --- a/Sharpmake/ExtensionMethods.cs +++ b/Sharpmake/ExtensionMethods.cs @@ -393,11 +393,18 @@ public static Version GetVisualStudioVCToolsVersion(this DevEnv visualVersion) return version; } + private static ConcurrentDictionary<(DevEnv, Platform), Version> s_visualStudioCompilerVersionCache = new ConcurrentDictionary<(DevEnv, Platform), 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); + var cacheKey = (visualVersion, platform); + Version version = s_visualStudioCompilerVersionCache.GetOrAdd(cacheKey, ((DevEnv, Platform) key) => + { + 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); + }); + return version; } ///