Skip to content

Latest commit

History

History
62 lines (45 loc) 路 2.32 KB

Readme.md

File metadata and controls

62 lines (45 loc) 路 2.32 KB

Visual Studio 2017+ Locator

Logo '?VS'

Nuget Package

A NuGet package to detect Visual Studio 2017+ installs from F# code similar to the vswhere binary.

Note: The API is also usable in other .NET languages but exposes some F# specific types

API

module BlackFox.VsWhere.VsInstances =
    /// Get all VS2017+ instances (Visual Studio stable, preview, Build tools, ...)
    /// This method return instances that have installation errors and pre-releases.
    let getAll (): VsSetupInstance list =

    /// Get VS2017+ instances that are completely installed
    let getCompleted (includePrerelease: bool): VsSetupInstance list =

    /// Get VS2017+ instances that are completely installed and have a specific package ID installed
    let getWithPackage (packageId: string) (includePrerelease: bool): VsSetupInstance list =

    /// Get legacy VS instances (before VS2017: VS .NET 2002 to VS2015).
    /// Note that the information for legacy ones is limited.
    let getLegacy(): VsSetupInstance list =

    /// Get all Visual Studio instances including legacy VS instances (before VS2017: VS .NET 2002 to VS2015).
    /// Note that the information for legacy ones is limited.
    let getAllWithLegacy (): VsSetupInstance list =

Package IDs for components and workloads are documented on docs.microsoft.com.

Sample usage

Find MSBuild:

let instance =
    VsInstances.getWithPackage "Microsoft.Component.MSBuild" false
    |> List.tryHead

match instance with
| None -> printfn "No MSBuild"
| Some vs ->
    let msbuild = Path.Combine(vs.InstallationPath, "MSBuild\\15.0\\Bin\\MSBuild.exe")
    printfn "MSBuild: %s" msbuild

Start Developer Command Prompt:

match VsInstances.getCompleted false |> List.tryHead with
| None -> printfn "No VS"
| Some vs ->
    let vsdevcmd = Path.Combine(vs.InstallationPath, "Common7\\Tools\\vsdevcmd.bat")
    let comspec = Environment.GetEnvironmentVariable("COMSPEC")
    Process.Start(comspec, sprintf "/k \"%s\"" vsdevcmd) |> ignore