Created
February 26, 2021 06:45
-
-
Save objectx/841f7fe5c60ffaa860a0565c5128d9aa to your computer and use it in GitHub Desktop.
Find installed cl.exe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "nuget: BlackFox.VsWhere" | |
open System.IO | |
open BlackFox.VsWhere | |
let findCL (includePrerelease: bool): Result<string, string> = | |
let vcComponent = "Microsoft.VisualStudio.Component.VC.Tools.x86.x64" | |
let versionTextPath = "VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt" | |
let instance = VsInstances.getWithPackage vcComponent includePrerelease |> List.tryHead | |
match instance with | |
| None -> | |
Error "missing component" | |
| Some p -> | |
let vpath = Path.Join (p.InstallationPath, versionTextPath) | |
try | |
let version = File.ReadLines vpath |> Seq.tryHead | |
match version with | |
| Some v -> | |
let clPath = Path.Join (p.InstallationPath, "VC/Tools/MSVC", v.Trim (), "bin/HostX64/x64/cl.exe") |> Path.GetFullPath | |
if File.Exists clPath then | |
Ok clPath | |
else | |
Error "missing cl.exe" | |
| None -> Error "no version information" | |
with | |
| :? FileNotFoundException as ex -> Error ex.Message | |
let cl = findCL true | |
match cl with | |
| Ok x -> printfn "cl.exe = \"%s\"" x | |
| Error msg -> printfn "failed to find cl.exe (reason = %s)" msg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment