Skip to content

Instantly share code, notes, and snippets.

@objectx
Created February 26, 2021 06:45
Show Gist options
  • Save objectx/841f7fe5c60ffaa860a0565c5128d9aa to your computer and use it in GitHub Desktop.
Save objectx/841f7fe5c60ffaa860a0565c5128d9aa to your computer and use it in GitHub Desktop.
Find installed cl.exe
#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